request-tracer 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTVmNmM4MmI3MjA5OWNlN2E5MzExYWQzMDZiMThlZWMxMWMyYTk3MA==
4
+ OGUzZDkyNTRiMGFjNTkzZGVhMzE3ZmRmMWFjNGRmZjM4NmQyNDBhZg==
5
5
  data.tar.gz: !binary |-
6
- NmIwNjM3MzZhYTg1NjdhMTEzOGNlYTdjZWE5MzFlY2VhYjU2N2M4Nw==
6
+ MzgyYTEzMmM0OTYyYTk1NDViYzc2NzExYWUyYTBlYmYwYWE5ZDM4NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmFiY2MwNTg4NzhlZDI0NjFkNzI3MGM1MWI2OTY5NzQzNzM4NTJiZGI1ZDJi
10
- OTVjZDhlMDcwZTJjYTNiOTc0MTkxZGQ2MTdjZWRmYTQ3NmFlN2MxNDAxY2Mw
11
- OWJlMDdmYWYyYmRmMDI0ZDM2M2E4ZTkyNWE3MzE0YmMwZmFiODg=
9
+ ZWY4MDVjMjRlZTI2MTMxMTYzOTA5ZTdhYTM1ZTIzZmZlYzBiMTlhNWYyMzMz
10
+ YTc0Zjg2MzFhZjQwNjE1MzYyYjM3MTc2M2I2Mjg3YjRjOTkzN2Y2MWQ0MmZl
11
+ NjMxZDY1OGQ1MzcyMTZhNmYzNjNhMzcxOThiYmRhY2QwNDgwNDA=
12
12
  data.tar.gz: !binary |-
13
- YjkxOTY0NmVkNGQzOWMxOGI0ZjBhMjAxNzc4MDFjMmU0YTZlNDlkMzYwZDNj
14
- ZWM1NjIyMzJiNThkNjIzNmUyYTU4ZTAwOWY3MjMwMzYzOGIwMGFlODU3YTMy
15
- ZjZmZjMzYzA2NTgyN2YwNzE5NzQ1NTRlN2M3ZjM5NjZjMmU5YWQ=
13
+ ZDZkZmI5NTcxNjNiYzI2ZjcwY2I2Y2VlZGE1ZjI2YTZhNDJmNTkxM2UxZTU4
14
+ MmZlZDAxYzRlNDMyNmQ5ZTc2NzAzMDY4ODcxNDE3MDVhMmQxZWFkYjRjZTBk
15
+ MGRjNjhhNjYxNmEyNjgwMDEzYjczZjIyNWFhZTliMzQ4NDQ2OTU=
@@ -1,9 +1,10 @@
1
1
  module RequestTracer
2
2
  module Integration
3
3
  module Base
4
+ HEADER_REGEX = /HTTP_X_B3_(.*)/
4
5
  def extract_fields_from_headers(header_hash)
5
6
  header_hash.map do |k,v|
6
- special_header = /HTTP_X_B3_(.*)/.match(k)
7
+ special_header = HEADER_REGEX.match(k)
7
8
  special_header && [B3_REQUIRED_FIELDS_FROM_SHORT_NAMES[special_header[1].downcase], v]
8
9
  end.compact.to_h
9
10
  end
@@ -25,8 +25,10 @@ module RequestTracer
25
25
 
26
26
  class ClientMiddleware
27
27
  def call(worker_class, job, queue, redis_pool)
28
- job['trace'] = Trace.latest.to_h
29
- yield
28
+ Trace.record do |trace|
29
+ job['trace'] = trace.to_h
30
+ yield
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -94,7 +94,7 @@ module RequestTracer
94
94
  end
95
95
 
96
96
  def push(trace_info)
97
- (yield ; return) unless trace_info
97
+ return yield unless trace_info
98
98
  trace = if trace_info.include?("trace_id") && trace_info.include?("span_id")
99
99
  TraceId.create(trace_info)
100
100
  else
@@ -1,3 +1,3 @@
1
1
  module RequestTracer
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -71,10 +71,14 @@ describe RequestTracer::Integration::SidekiqHandler do
71
71
  end
72
72
  end
73
73
  context "when there is an existing trace" do
74
- before { RequestTracer::Trace.push trace.to_h }
75
- it "passes the trace from the main process to the worker and records the worker" do
74
+ let(:subtrace) { trace.next_id }
75
+ before do
76
+ RequestTracer::Trace.push trace.to_h
77
+ allow(RequestTracer::Trace).to receive(:record).and_yield(subtrace)
78
+ end
79
+ it "passes a sub-trace from the main process to the worker and pushes this on the trace stack in the worker" do
76
80
  TraceableJob.perform_async('foo')
77
- expect(result_checker.traces).to eq([trace.to_h])
81
+ expect(result_checker.traces).to eq([subtrace.to_h])
78
82
  end
79
83
  end
80
84
  it "calls the job with the originally given parameters" do
@@ -91,7 +95,7 @@ describe RequestTracer::Integration::SidekiqHandler do
91
95
  end
92
96
  context "when there is an existing trace" do
93
97
  before { RequestTracer::Trace.push trace.to_h }
94
- it "passes the trace from the main process to the worker and records the worker" do
98
+ it "does not pass the trace from the main process to the worker and records the worker" do
95
99
  TraceableJob.perform_async('foo')
96
100
  expect(result_checker.traces).to eq([{}])
97
101
  end
@@ -106,7 +110,7 @@ describe RequestTracer::Integration::SidekiqHandler do
106
110
  end
107
111
  context "when there is an existing trace" do
108
112
  before { RequestTracer::Trace.push trace.to_h }
109
- it "passes the trace from the main process to the worker and records the worker" do
113
+ it "does not pass the trace from the main process to the worker and records the worker" do
110
114
  TraceableJob.perform_async('foo')
111
115
  expect(result_checker.traces).to eq([{}])
112
116
  end
@@ -51,9 +51,17 @@ describe RequestTracer::Trace do
51
51
  def push(&blk)
52
52
  described_class.push(previous_trace_hash, &blk)
53
53
  end
54
+ shared_examples "returning the block value" do
55
+ let(:block_value) { rand(1000) }
56
+ it 'returns the value from the block' do
57
+ returned = push {|t| block_value }
58
+ expect(returned).to eq(block_value)
59
+ end
60
+ end
54
61
  context 'when trace_hash contains a previous trace' do
55
62
  let(:previous_trace) { described_class.create}
56
63
  let(:previous_trace_hash) { previous_trace.to_h }
64
+ it_behaves_like "returning the block value"
57
65
  it 'keeps the span_id' do
58
66
  push do |t|
59
67
  expect(t.span_id).to eq(previous_trace.span_id)
@@ -72,6 +80,7 @@ describe RequestTracer::Trace do
72
80
  end
73
81
  context 'when no previous trace exists' do
74
82
  let(:previous_trace_hash) { {} }
83
+ it_behaves_like "returning the block value"
75
84
  it 'creates a new span_id' do
76
85
  push do |t|
77
86
  expect(t.span_id.i64.to_s).to match /[0-9a-z]+/i
@@ -88,5 +97,9 @@ describe RequestTracer::Trace do
88
97
  end
89
98
  end
90
99
  end
100
+ context 'when called with nil' do
101
+ let(:previous_trace_hash) { nil }
102
+ it_behaves_like "returning the block value"
103
+ end
91
104
  end
92
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
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-03-03 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client