request-tracer 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.rspec +3 -0
- data/Guardfile +1 -1
- data/lib/request_tracer/trace.rb +7 -5
- data/lib/request_tracer/version.rb +1 -1
- data/lib/request_tracer.rb +0 -7
- data/request-tracer.gemspec +1 -0
- data/spec/lib/request_tracer/trace_spec.rb +92 -0
- metadata +48 -32
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjhhMTU0YjYxYTg5ZTk0NmRjM2U1NzM3MWUwNjFhODc4NjUzZDIwNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTI2MWRiNWE2NmJkNDIwZTgzMjJiYWVjMWZmNGQ5OTRjOGNkMzJkMg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWMyZTJiMmE2ODJhM2E1NTEwZDg3NjYyNTI2YzgwZjY0OGRmM2QwZTY4ZjM5
|
10
|
+
MTU1MDMzMmVmNWM5NGQxZDFjNjE2MjU0M2JmNWEyMDhhZjg1NDIwZTJkNzlj
|
11
|
+
Yzk2Zjg2YWQ3ZmRkOTY5ODkyMzUzNzYyNjgwOTU0MDdmZjgxYTk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZTUxYzlkY2U5NTQ2MGNiMTc2OWRhMDcyYzVjNDRhYWE2NTQ4ZTY1OWRhZTg4
|
14
|
+
YWZmNTQ4MjZmNzA2MTg1MmQ4YWM3NWExOGRlNWRkOGIwNjllOWI2OGFjNmRm
|
15
|
+
OWQ1NGUwODU3YzgxYTg0MmQ3OGIxZjM4MTMzMDI2NWQ3MzFhYzA=
|
data/.rspec
CHANGED
data/Guardfile
CHANGED
@@ -10,7 +10,7 @@ guard :bundler do
|
|
10
10
|
files.each { |file| watch(helper.real_path(file)) }
|
11
11
|
end
|
12
12
|
|
13
|
-
guard :rspec, cmd: "bundle exec rspec -t focus" do
|
13
|
+
guard :rspec, cmd: "GENERATIVE_COUNT=5 bundle exec rspec -t focus" do
|
14
14
|
require "guard/rspec/dsl"
|
15
15
|
dsl = Guard::RSpec::Dsl.new(self)
|
16
16
|
|
data/lib/request_tracer/trace.rb
CHANGED
@@ -28,6 +28,7 @@ module RequestTracer
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
attr_reader :value, :i64
|
31
32
|
def initialize(value)
|
32
33
|
@value = value
|
33
34
|
@i64 = if @value > MAX_SIGNED_I64
|
@@ -37,6 +38,9 @@ module RequestTracer
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
41
|
+
def ==(other_span)
|
42
|
+
other_span&.value == @value
|
43
|
+
end
|
40
44
|
def to_s; "%016x" % @value; end
|
41
45
|
def to_i; @i64; end
|
42
46
|
end
|
@@ -78,9 +82,7 @@ module RequestTracer
|
|
78
82
|
|
79
83
|
def create
|
80
84
|
span_id = generate_id
|
81
|
-
|
82
|
-
stack.push(trace_id)
|
83
|
-
trace_id
|
85
|
+
TraceId.new(span_id, nil, span_id)
|
84
86
|
end
|
85
87
|
|
86
88
|
def latest
|
@@ -88,7 +90,7 @@ module RequestTracer
|
|
88
90
|
end
|
89
91
|
|
90
92
|
def latest_or_create
|
91
|
-
latest || create
|
93
|
+
latest || stack.push(create)
|
92
94
|
end
|
93
95
|
|
94
96
|
def push(trace_info)
|
@@ -127,7 +129,7 @@ module RequestTracer
|
|
127
129
|
end
|
128
130
|
|
129
131
|
def record(annotation = nil, &block)
|
130
|
-
tracer.record(latest
|
132
|
+
tracer.record(latest&.next_id || create, annotation, &block)
|
131
133
|
end
|
132
134
|
|
133
135
|
def tracer=(tracer)
|
data/lib/request_tracer.rb
CHANGED
data/request-tracer.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
21
21
|
spec.add_development_dependency 'rake', '~> 10.0'
|
22
22
|
spec.add_development_dependency "rspec", "~> 3.4"
|
23
|
+
spec.add_development_dependency "generative"
|
23
24
|
spec.add_development_dependency "rack-test", "~> 0.6"
|
24
25
|
spec.add_development_dependency "webmock"
|
25
26
|
spec.add_development_dependency "guard", "~> 2.13"
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'request_tracer/trace'
|
2
|
+
|
3
|
+
describe RequestTracer::Trace do
|
4
|
+
let(:trace_stack_size) { rand(2) }
|
5
|
+
let(:trace_stack) do
|
6
|
+
(1..trace_stack_size).inject([]) do |stack, i|
|
7
|
+
stack + [stack.last&.next_id || described_class.create]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
before do
|
11
|
+
described_class.clear
|
12
|
+
trace_stack.each {|s| described_class.push(s.to_h) }
|
13
|
+
end
|
14
|
+
context '#record', generative: true, order: :generative do
|
15
|
+
def record(&blk)
|
16
|
+
described_class.record(&blk)
|
17
|
+
end
|
18
|
+
it 'generates a new span_id for the scope of the block' do
|
19
|
+
temp_span = record do |t|
|
20
|
+
expect(t.span_id).not_to eq(trace_stack.last&.span_id)
|
21
|
+
expect(described_class.latest).to eq(t)
|
22
|
+
t
|
23
|
+
end
|
24
|
+
expect(described_class.latest).not_to eq(temp_span)
|
25
|
+
end
|
26
|
+
it 'takes the old span_id as the parent_span_id' do
|
27
|
+
temp_span = record do |t|
|
28
|
+
expect(t.parent_id).to eq(trace_stack.last&.span_id)
|
29
|
+
t
|
30
|
+
end
|
31
|
+
expect(described_class.latest&.span_id).to eq(temp_span.parent_id)
|
32
|
+
end
|
33
|
+
context 'when no previous trace exists' do
|
34
|
+
let(:trace_stack_size) { 0 }
|
35
|
+
it 'generates a new trace_id' do
|
36
|
+
record do |t|
|
37
|
+
expect(t.trace_id.i64.to_s).to match /[0-9a-z]+/i
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context 'when a previous trace exists' do
|
42
|
+
let(:trace_stack_size) { 1 }
|
43
|
+
it 'reuses the existing trace_id' do
|
44
|
+
record do |t|
|
45
|
+
expect(t.trace_id).to eq(trace_stack.last.trace_id)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
context '#push(trace_hash)', generative: true, order: :generative do
|
51
|
+
def push(&blk)
|
52
|
+
described_class.push(previous_trace_hash, &blk)
|
53
|
+
end
|
54
|
+
context 'when trace_hash contains a previous trace' do
|
55
|
+
let(:previous_trace) { described_class.create}
|
56
|
+
let(:previous_trace_hash) { previous_trace.to_h }
|
57
|
+
it 'keeps the span_id' do
|
58
|
+
push do |t|
|
59
|
+
expect(t.span_id).to eq(previous_trace.span_id)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
it 'keeps the parent_span_id' do
|
63
|
+
push do |t|
|
64
|
+
expect(t.parent_id).to eq(previous_trace.parent_id)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
it 'keeps the trace_id' do
|
68
|
+
push do |t|
|
69
|
+
expect(t.trace_id).to eq(previous_trace.trace_id)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
context 'when no previous trace exists' do
|
74
|
+
let(:previous_trace_hash) { {} }
|
75
|
+
it 'creates a new span_id' do
|
76
|
+
push do |t|
|
77
|
+
expect(t.span_id.i64.to_s).to match /[0-9a-z]+/i
|
78
|
+
end
|
79
|
+
end
|
80
|
+
it 'creates a new trace_id' do
|
81
|
+
push do |t|
|
82
|
+
expect(t.trace_id.i64.to_s).to match /[0-9a-z]+/i
|
83
|
+
end
|
84
|
+
end
|
85
|
+
it 'does not set a parent_span_id' do
|
86
|
+
push do |t|
|
87
|
+
expect(t.parent_id).to eq(nil)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request-tracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Mauch
|
@@ -14,168 +14,182 @@ dependencies:
|
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: generative
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rack-test
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- -
|
87
|
+
- - ~>
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: '0.6'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- -
|
94
|
+
- - ~>
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0.6'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: webmock
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- -
|
101
|
+
- - ! '>='
|
88
102
|
- !ruby/object:Gem::Version
|
89
103
|
version: '0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- -
|
108
|
+
- - ! '>='
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: guard
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- -
|
115
|
+
- - ~>
|
102
116
|
- !ruby/object:Gem::Version
|
103
117
|
version: '2.13'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- -
|
122
|
+
- - ~>
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '2.13'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: guard-rspec
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
|
-
- -
|
129
|
+
- - ~>
|
116
130
|
- !ruby/object:Gem::Version
|
117
131
|
version: '4.6'
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
|
-
- -
|
136
|
+
- - ~>
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '4.6'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: guard-bundler
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
|
-
- -
|
143
|
+
- - ~>
|
130
144
|
- !ruby/object:Gem::Version
|
131
145
|
version: '2.1'
|
132
146
|
type: :development
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
|
-
- -
|
150
|
+
- - ~>
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '2.1'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: geminabox
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
|
-
- -
|
157
|
+
- - ! '>='
|
144
158
|
- !ruby/object:Gem::Version
|
145
159
|
version: '0'
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
|
-
- -
|
164
|
+
- - ! '>='
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '0'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: gem-release
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
156
170
|
requirements:
|
157
|
-
- -
|
171
|
+
- - ! '>='
|
158
172
|
- !ruby/object:Gem::Version
|
159
173
|
version: '0'
|
160
174
|
type: :development
|
161
175
|
prerelease: false
|
162
176
|
version_requirements: !ruby/object:Gem::Requirement
|
163
177
|
requirements:
|
164
|
-
- -
|
178
|
+
- - ! '>='
|
165
179
|
- !ruby/object:Gem::Version
|
166
180
|
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: pry
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
170
184
|
requirements:
|
171
|
-
- -
|
185
|
+
- - ! '>='
|
172
186
|
- !ruby/object:Gem::Version
|
173
187
|
version: '0'
|
174
188
|
type: :development
|
175
189
|
prerelease: false
|
176
190
|
version_requirements: !ruby/object:Gem::Requirement
|
177
191
|
requirements:
|
178
|
-
- -
|
192
|
+
- - ! '>='
|
179
193
|
- !ruby/object:Gem::Version
|
180
194
|
version: '0'
|
181
195
|
description: This is a tracer that hooks into several components to allow tracing
|
@@ -186,10 +200,10 @@ executables: []
|
|
186
200
|
extensions: []
|
187
201
|
extra_rdoc_files: []
|
188
202
|
files:
|
189
|
-
-
|
190
|
-
-
|
191
|
-
-
|
192
|
-
-
|
203
|
+
- .gemrelease
|
204
|
+
- .gitignore
|
205
|
+
- .rspec
|
206
|
+
- .travis.yml
|
193
207
|
- Gemfile
|
194
208
|
- Guardfile
|
195
209
|
- LICENSE
|
@@ -205,6 +219,7 @@ files:
|
|
205
219
|
- spec/integration/integration_spec.rb
|
206
220
|
- spec/lib/request_tracer/integration/rack_handler_spec.rb
|
207
221
|
- spec/lib/request_tracer/integration/rest_client_handler_spec.rb
|
222
|
+
- spec/lib/request_tracer/trace_spec.rb
|
208
223
|
- spec/spec_helper.rb
|
209
224
|
- spec/support/test_app.rb
|
210
225
|
- spec/support/test_app_config.ru
|
@@ -218,17 +233,17 @@ require_paths:
|
|
218
233
|
- lib
|
219
234
|
required_ruby_version: !ruby/object:Gem::Requirement
|
220
235
|
requirements:
|
221
|
-
- -
|
236
|
+
- - ! '>='
|
222
237
|
- !ruby/object:Gem::Version
|
223
238
|
version: '0'
|
224
239
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
240
|
requirements:
|
226
|
-
- -
|
241
|
+
- - ! '>='
|
227
242
|
- !ruby/object:Gem::Version
|
228
243
|
version: '0'
|
229
244
|
requirements: []
|
230
245
|
rubyforge_project:
|
231
|
-
rubygems_version: 2.5
|
246
|
+
rubygems_version: 2.4.5
|
232
247
|
signing_key:
|
233
248
|
specification_version: 4
|
234
249
|
summary: Traces requests using the Zipkin HTTP headers
|
@@ -236,6 +251,7 @@ test_files:
|
|
236
251
|
- spec/integration/integration_spec.rb
|
237
252
|
- spec/lib/request_tracer/integration/rack_handler_spec.rb
|
238
253
|
- spec/lib/request_tracer/integration/rest_client_handler_spec.rb
|
254
|
+
- spec/lib/request_tracer/trace_spec.rb
|
239
255
|
- spec/spec_helper.rb
|
240
256
|
- spec/support/test_app.rb
|
241
257
|
- spec/support/test_app_config.ru
|