lhc 8.1.0 → 8.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '059dd1e79e371a3df375a6a565b4797c11bf71da'
4
- data.tar.gz: b2a5925b099b34812d6cb1aef256290d0cace0e5
3
+ metadata.gz: b44be8ec6523410f4c54ef36a395e1087030257a
4
+ data.tar.gz: 27f513d349a857372dba50b22b70bd36b9c5766d
5
5
  SHA512:
6
- metadata.gz: aff5120baa514889103791b6681e4776bbf8e5055db5c8b126fae5580487f72da833d3a472fd15b8c930807a1500d58e4a1c3c7c7c332ed47b8f9d460d2ac36d
7
- data.tar.gz: a9959d2b3c84fd4125fe682eb172d6e06b81c225758931a0b493a7dadfa6a6b0faf4460e6a5ae7424482351a4fc8596312b22d6cabffe74e3de5952d16472303
6
+ metadata.gz: f37ea9b11ecb0385761daefbe496be873c3a171c7f89ef04ce4e47e547e7cd5ed355905372d1f90dffe8cf24871a229260614a1001354c4b9eb4603a9df5dc1b
7
+ data.tar.gz: afca207fb2293a769242ad8ee9d80b5b9db4625cbe7ab6962c0128f15b2db0f0fa6141ace620d6d3c4bc1b59f35d16e47b40cb6c90357f071de91142bd2c2986
@@ -11,13 +11,16 @@ class LHC::Zipkin < LHC::Interceptor
11
11
  def before_request
12
12
  return unless dependencies?
13
13
  ZipkinTracer::TraceContainer.with_trace_id(trace_id) do
14
+ # add headers even if the current trace_id should not be sampled
14
15
  B3_HEADERS.each { |method, header| request.headers[header] = trace_id.send(method).to_s }
16
+ # only sample the current call if we're instructed to do so
15
17
  start_trace! if ::Trace.tracer && trace_id.sampled?
16
18
  end
17
19
  end
18
20
 
19
21
  def after_response
20
- return unless dependencies?
22
+ # only sample the current call if we're instructed to do so
23
+ return unless dependencies? && trace_id.sampled?
21
24
  end_trace!
22
25
  end
23
26
 
@@ -39,6 +42,7 @@ class LHC::Zipkin < LHC::Interceptor
39
42
  @trace_id ||= ZipkinTracer::TraceGenerator.new.next_trace_id
40
43
  end
41
44
 
45
+ # register a new span with zipkin tracer
42
46
  def span
43
47
  @span ||= ::Trace.tracer.start_span(trace_id, url.path)
44
48
  end
@@ -1,3 +1,3 @@
1
1
  module LHC
2
- VERSION ||= '8.1.0'
2
+ VERSION ||= '8.1.1'
3
3
  end
@@ -13,7 +13,7 @@ describe LHC::Zipkin do
13
13
  trace_id: 'trace_id',
14
14
  parent_id: 'parent_id',
15
15
  span_id: 'span_id',
16
- sampled: 'sampled',
16
+ sampled: true,
17
17
  flags: 'flags'
18
18
  )
19
19
  end
@@ -23,7 +23,7 @@ describe LHC::Zipkin do
23
23
  expect(headers['X-B3-TraceId']).to eq('trace_id')
24
24
  expect(headers['X-B3-ParentSpanId']).to eq('parent_id')
25
25
  expect(headers['X-B3-SpanId']).to eq('span_id')
26
- expect(headers['X-B3-Sampled']).to eq('sampled')
26
+ expect(headers['X-B3-Sampled']).to eq('true')
27
27
  expect(headers['X-B3-Flags']).to eq('flags')
28
28
  end
29
29
  end
@@ -49,4 +49,60 @@ describe LHC::Zipkin do
49
49
  expect(headers['X-B3-Flags']).to be_nil
50
50
  end
51
51
  end
52
+
53
+ describe 'creating new spans' do
54
+ context 'sampled? is false' do
55
+ before(:all) do
56
+ ::ZipkinTracer::TraceContainer.setup_mock(
57
+ trace_id: 'trace_id',
58
+ parent_id: 'parent_id',
59
+ span_id: 'span_id',
60
+ sampled: false,
61
+ flags: 'flags'
62
+ )
63
+ end
64
+
65
+ it 'adds the proper X-B3 headers' do
66
+ headers = LHC.get(:local).request.headers
67
+ expect(headers['X-B3-TraceId']).to eq('trace_id')
68
+ expect(headers['X-B3-ParentSpanId']).to eq('parent_id')
69
+ expect(headers['X-B3-SpanId']).to eq('span_id')
70
+ expect(headers['X-B3-Sampled']).to eq('false')
71
+ expect(headers['X-B3-Flags']).to eq('flags')
72
+ end
73
+
74
+ it 'does not register a new span' do
75
+ # ensure no span was registered, by checking no call on span
76
+ expect_any_instance_of(described_class).not_to receive(:span).and_call_original
77
+ LHC.get(:local)
78
+ end
79
+ end
80
+
81
+ context 'sampled? is true' do
82
+ before(:all) do
83
+ ::ZipkinTracer::TraceContainer.setup_mock(
84
+ trace_id: 'trace_id',
85
+ parent_id: 'parent_id',
86
+ span_id: 'span_id',
87
+ sampled: true,
88
+ flags: 'flags'
89
+ )
90
+ end
91
+
92
+ it 'adds the proper X-B3 headers' do
93
+ headers = LHC.get(:local).request.headers
94
+ expect(headers['X-B3-TraceId']).to eq('trace_id')
95
+ expect(headers['X-B3-ParentSpanId']).to eq('parent_id')
96
+ expect(headers['X-B3-SpanId']).to eq('span_id')
97
+ expect(headers['X-B3-Sampled']).to eq('true')
98
+ expect(headers['X-B3-Flags']).to eq('flags')
99
+ end
100
+
101
+ it 'does register a new span' do
102
+ # ensure a span was registered, by checking call on span
103
+ expect_any_instance_of(described_class).to receive(:span).at_least(1).times.and_call_original
104
+ LHC.get(:local)
105
+ end
106
+ end
107
+ end
52
108
  end
@@ -42,7 +42,7 @@ module ZipkinTracer
42
42
  end
43
43
 
44
44
  def sampled
45
- 'sampled'
45
+ ZipkinTracer::TraceContainer.current.sampled
46
46
  end
47
47
 
48
48
  def flags
@@ -50,7 +50,7 @@ module ZipkinTracer
50
50
  end
51
51
 
52
52
  def sampled?
53
- true
53
+ ZipkinTracer::TraceContainer.current.sampled
54
54
  end
55
55
  end
56
56
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhc
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.0
4
+ version: 8.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhc/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-12 00:00:00.000000000 Z
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus