request-tracer 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MmQ3Njk0NWZiZjljMzgzZGFjMWIyY2I5MzBjZThjYjQ0OTAwODFkOQ==
5
- data.tar.gz: !binary |-
6
- ZTZkMWQwMmJhNzM1MjAxNTIyMmE4ZTgzYTA1NDZlMjM5M2UwNzMwZQ==
2
+ SHA1:
3
+ metadata.gz: 568a644828b5c78478ff4347ca98b3203953db48
4
+ data.tar.gz: 9c78a78c1c80c8b212755c6f8588d02f26380a54
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MTNmZGZiNWZmNDE3OTJlN2U5N2ZlNThlOTZmMjdiMjZhYmUwZTg3NTZhZjY0
10
- YzU3ZGM4OGY2NWI3MWIzMTZlNWZhZGY3M2U1ZTRmMTBlZjQ3YzhjNjk1NDFm
11
- NDhkNmU4MTM2NGIxZTZjZTMzMGYxMTUwYTQzYmRmMTMxZTFkYjM=
12
- data.tar.gz: !binary |-
13
- MDRkZTViNGE3ZTAyOGY2YTRjNjA3NzY3MGUwYTA3Nzg0MTM5YTJhZTAwYjZk
14
- NmUxNTBmMzNiOTZjMDIzY2Y3YTQ1ZmJhOWI5OTA3OGRlYWFmNDM3NDUyMjQ4
15
- MThkNWI0NTQ2OGE5OTlhZDAzZDVkYzIzM2IwMThmYjg4NjE5NTU=
6
+ metadata.gz: 0f15bd2e483b3497bf50e2662523cf72f63f1d32dd26ea044d56395200d33f1551ab0b28638ef51f2b5dd83cfc1f7afce25257378fb39a533ff4c3e64b6d0539
7
+ data.tar.gz: 996680db6d55f1c75c3c02ec2f3655ba9774645b8e934f96edb3df84ed813dfe7092bcdd3c4e0ffb12945c1f0ed0fc32046b9676dd307dd297db7d67abbea2ec
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper.rb
@@ -9,7 +9,7 @@ module RequestTracer
9
9
  @tracer = config[:tracer] || Trace
10
10
  end
11
11
  def call(env)
12
- @tracer.record(extract_fields_from_headers(env)) do
12
+ @tracer.push(extract_fields_from_headers(env)) do
13
13
  @app.call(env)
14
14
  end
15
15
  end
@@ -8,7 +8,9 @@ module RequestTracer
8
8
  def activate
9
9
  require 'rest-client'
10
10
  RestClient.add_before_execution_proc do |req, params|
11
- extract_headers_from_fields(Trace.latest).each {|h, v| req[h] = v}
11
+ Trace.record do |trace|
12
+ extract_headers_from_fields(trace).each {|h, v| req[h] = v}
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -48,6 +48,9 @@ module RequestTracer
48
48
  span_id = Trace.generate_id
49
49
  self.new(h["trace_id"] || span_id, h["span_id"], Trace.generate_id)
50
50
  end
51
+ def self.create(h)
52
+ self.new(h["trace_id"], h["parent_span_id"], h["span_id"])
53
+ end
51
54
  def initialize(trace_id, parent_id, span_id)
52
55
  @trace_id = SpanId.from_value(trace_id)
53
56
  @parent_id = parent_id && SpanId.from_value(parent_id)
@@ -73,21 +76,31 @@ module RequestTracer
73
76
  end
74
77
  end
75
78
 
79
+ def create
80
+ span_id = generate_id
81
+ trace_id = TraceId.new(span_id, nil, span_id)
82
+ stack.push(trace_id)
83
+ trace_id
84
+ end
76
85
 
77
86
  def latest
78
- if stack.empty?
79
- span_id = generate_id
80
- trace_id = TraceId.new(span_id, nil, span_id)
81
- stack.push(trace_id)
82
- end
83
87
  stack.last
84
88
  end
85
89
 
90
+ def latest_or_create
91
+ latest || create
92
+ end
93
+
86
94
  def push(trace_info)
87
- stack.push(TraceId.spawn_from_hash(trace_info))
95
+ trace = if trace_info.include?("trace_id") && trace_info.include?("span_id")
96
+ TraceId.create(trace_info)
97
+ else
98
+ TraceId.spawn_from_hash(trace_info)
99
+ end
100
+ stack.push(trace)
88
101
  if block_given?
89
102
  begin
90
- yield
103
+ yield trace
91
104
  ensure
92
105
  pop
93
106
  end
@@ -98,6 +111,10 @@ module RequestTracer
98
111
  stack.pop
99
112
  end
100
113
 
114
+ def clear
115
+ stack.clear
116
+ end
117
+
101
118
  def unwind
102
119
  if block_given?
103
120
  begin
@@ -109,12 +126,8 @@ module RequestTracer
109
126
  end
110
127
  end
111
128
 
112
- def record(annotation, &block)
113
- tracer.record(latest, annotation, &block)
114
- end
115
-
116
- def set_rpc_name(name)
117
- tracer.set_rpc_name(latest, name) unless stack.empty?
129
+ def record(annotation = nil, &block)
130
+ tracer.record(latest.next_id, annotation, &block)
118
131
  end
119
132
 
120
133
  def tracer=(tracer)
@@ -150,9 +163,9 @@ module RequestTracer
150
163
  end
151
164
 
152
165
  class DefaultTracer
153
- def record(*args, &block)
154
- Trace.push(args[1].to_h) do
155
- block.call
166
+ def record(latest_trace, annotation, &block)
167
+ Trace.push(latest_trace.to_h) do |trace|
168
+ block.call(trace)
156
169
  end
157
170
  end
158
171
  end
@@ -1,3 +1,3 @@
1
1
  module RequestTracer
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -14,4 +14,11 @@ module RequestTracer
14
14
  integration_module.activate
15
15
  end
16
16
  end
17
+ def self.annotate(annotation)
18
+
19
+ end
20
+
21
+ def self.record(annotation=nil, &blk)
22
+
23
+ end
17
24
  end
@@ -22,7 +22,7 @@ describe RequestTracer::Integration::RackHandler do
22
22
  end
23
23
 
24
24
  before do
25
- allow(tracer).to receive(:record) {|&block| block.call }
25
+ allow(tracer).to receive(:push) {|&block| block.call }
26
26
  end
27
27
 
28
28
  shared_examples_for 'traces the request' do
@@ -33,7 +33,7 @@ describe RequestTracer::Integration::RackHandler do
33
33
  get '/'
34
34
  expect(last_response.status).to eq(200)
35
35
  expect(last_response.body).to eq('hello')
36
- expect(tracer).to have_received(:record).with(extract_fields_from_headers(trace_headers))
36
+ expect(tracer).to have_received(:push).with(extract_fields_from_headers(trace_headers))
37
37
  end
38
38
  end
39
39
 
@@ -1,23 +1,26 @@
1
- require 'rack/mock'
2
1
  require 'rack/test'
3
- require 'spec_helper'
4
2
  require 'request_tracer/trace'
5
- require 'logger'
3
+ require 'request_tracer/integration/rest_client_handler'
6
4
  require 'webmock/rspec'
7
- require 'rest-client'
8
5
 
9
6
  describe RequestTracer::Integration::RestClientHandler do
10
7
  include RequestTracer::Integration::Base
11
8
  RequestTracer.integrate_with(:rest_client)
12
9
  before(:all) { WebMock.disable_net_connect! }
10
+
11
+ let(:trace) { RequestTracer::Trace.create }
12
+
13
13
  before do
14
+ RequestTracer::Trace.clear
14
15
  stub_request(:any, "www.example.com")
16
+ allow(RequestTracer::Trace).to receive(:record).and_yield(trace)
17
+ RestClient.get("www.example.com")
15
18
  end
16
19
 
17
- let(:trace) { RequestTracer::Trace.latest }
18
- it "should have set the headers on the outgoing call" do
19
- RestClient.get("www.example.com")
20
- expect(WebMock).to have_requested(:get, "www.example.com").
21
- with(headers: extract_headers_from_fields(trace.to_h))
20
+ context "when no previous trace existed on the stack" do
21
+ it "sets fresh trace headers on the outgoing call" do
22
+ expect(WebMock).to have_requested(:get, "www.example.com").
23
+ with(headers: extract_headers_from_fields(trace.to_h))
24
+ end
22
25
  end
23
26
  end
metadata CHANGED
@@ -1,181 +1,181 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Mauch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-19 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.7'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.4'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.4'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.6'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.6'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '2.13'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2.13'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: guard-rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '4.6'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '4.6'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: guard-bundler
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
131
  version: '2.1'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '2.1'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: geminabox
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ! '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ! '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: gem-release
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ! '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ! '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: pry
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ! '>='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ! '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  description: This is a tracer that hooks into several components to allow tracing
@@ -186,9 +186,10 @@ executables: []
186
186
  extensions: []
187
187
  extra_rdoc_files: []
188
188
  files:
189
- - .gemrelease
190
- - .gitignore
191
- - .travis.yml
189
+ - ".gemrelease"
190
+ - ".gitignore"
191
+ - ".rspec"
192
+ - ".travis.yml"
192
193
  - Gemfile
193
194
  - Guardfile
194
195
  - LICENSE
@@ -217,17 +218,17 @@ require_paths:
217
218
  - lib
218
219
  required_ruby_version: !ruby/object:Gem::Requirement
219
220
  requirements:
220
- - - ! '>='
221
+ - - ">="
221
222
  - !ruby/object:Gem::Version
222
223
  version: '0'
223
224
  required_rubygems_version: !ruby/object:Gem::Requirement
224
225
  requirements:
225
- - - ! '>='
226
+ - - ">="
226
227
  - !ruby/object:Gem::Version
227
228
  version: '0'
228
229
  requirements: []
229
230
  rubyforge_project:
230
- rubygems_version: 2.4.5
231
+ rubygems_version: 2.5.1
231
232
  signing_key:
232
233
  specification_version: 4
233
234
  summary: Traces requests using the Zipkin HTTP headers