request-tracer 0.5.8 → 0.6.1

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
- ODhiNWZjMmY0OWNiNTk2YTMyYjIyMjMwMWI2NzVmN2M0MmIxZWM0ZQ==
4
+ MjI4YWIwMjlhZDY5ODZlMGI2OTBiZjJkNjY0YTUzNmUyNWNkODdhOQ==
5
5
  data.tar.gz: !binary |-
6
- MDgyOGNiZjM3NjYxNGEzMmMyN2U0NTI4ZTA0N2M2ZTBmMTc0ODlhYg==
6
+ ZjAzNWJiYTczOTQxMzAyMWNkYzZiMDdjOTkwNTgzODUwY2EzYzQyNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGVhYTBiM2MzNzJkMjc3MTVhOTc0MDQxZDc0ZmY4ODg3ODUyMmMyNzU5ZTYx
10
- MGRmNGQ5OTU4ODI1MTNjODY1OWY0MDJjOGY4NGEwYTNmOTgwODhhMWE3NjNj
11
- YWMxMTIwNzNlNjJiNWYzYjI2MWEzNTE2NTI2Njc0ZWUxYjE0OTE=
9
+ YWRjMzFmNTFkOGRlYjgwNjliM2JjZGRiYTE4Njk2YzhkZTBkOTJhZGNlYTNm
10
+ NjQ0ZTFlMTUzZmU1NTkwYzQwZjVlNDk4NTg3MjVmNzU0MmFjOGJhNDcxOWM5
11
+ MDlmZDk5M2VkMDNmNDJhMjAwZjhjNjg2OWVlY2VmNzc2YjNkNjc=
12
12
  data.tar.gz: !binary |-
13
- MmU2YTc0NTFkMzE4MzczMWRlNmVjNDc5MWRhYmI0OWRlNDM5ZDRkMzBmMjVm
14
- NWY3MDk4MzVkMmJmMDQ5ZmJmY2MxNzM0MzY0MGJiMGU5MjY2ZDY3NGNiNTcx
15
- NjAxOTIxNTRhYTI4NTRjYWQzZjZlMDI2NTIyNDY2OTJjYzFjNTk=
13
+ YzU1YjlkYjEwNDI0ZjIyYjViMGFkM2JiOWY0NDhmOTdkZWIwODMxYTQ4YTFk
14
+ OWM0ODliNTczZWQyNDg5MDZkOTQwOWU1Zjc2MDBhOTMyMTQ2MDQ3MGIyMDI1
15
+ MWU1MzFkZDZjMzMxYTQ5ZGY3OWEyZTI2ODkwNzE5YzU4MDU3MDE=
@@ -0,0 +1,38 @@
1
+ require_relative 'base'
2
+ require_relative '../trace'
3
+ module RequestTracer
4
+ module Integration
5
+ module SidekiqHandler
6
+ include Base
7
+ extend self
8
+ def activate
9
+ require 'sidekiq'
10
+ Sidekiq.configure_server do |config|
11
+ config.server_middleware do |chain|
12
+ chain.add ServerMiddleware
13
+ end
14
+ end
15
+ Sidekiq.configure_client do |config|
16
+ config.client_middleware do |chain|
17
+ chain.add ClientMiddleware
18
+ end
19
+ end
20
+ end
21
+
22
+ class ServerMiddleware
23
+ def call(worker, msg, queue)
24
+ Trace.push(msg["trace"]) do |trace|
25
+ yield
26
+ end
27
+ end
28
+ end
29
+
30
+ class ClientMiddleware
31
+ def call(worker_class, job, queue, redis_pool)
32
+ job['trace'] = Trace.latest.to_h
33
+ yield
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -94,6 +94,7 @@ module RequestTracer
94
94
  end
95
95
 
96
96
  def push(trace_info)
97
+ (yield ; return) unless trace_info
97
98
  trace = if trace_info.include?("trace_id") && trace_info.include?("span_id")
98
99
  TraceId.create(trace_info)
99
100
  else
@@ -1,3 +1,3 @@
1
1
  module RequestTracer
2
- VERSION = "0.5.8"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_development_dependency 'rest-client'
20
+ spec.add_development_dependency 'sidekiq'
20
21
  spec.add_development_dependency 'bundler', '~> 1.7'
21
22
  spec.add_development_dependency 'rake', '~> 10.0'
22
23
  spec.add_development_dependency "rspec", "~> 3.4"
@@ -0,0 +1,115 @@
1
+ require 'request_tracer/trace'
2
+ require 'request_tracer/integration/sidekiq_handler'
3
+ require 'sidekiq/testing'
4
+ Sidekiq.logger = Logger.new('/tmp/sidekiq.log')
5
+
6
+
7
+ describe RequestTracer::Integration::SidekiqHandler do
8
+ include RequestTracer::Integration::Base
9
+
10
+ class ResultChecker
11
+ attr_reader :traces, :job_args
12
+ def initialize
13
+ @traces = []
14
+ @job_args = []
15
+ end
16
+ def push_trace(trace)
17
+ @traces.push(trace)
18
+ end
19
+ def push_job_args(args)
20
+ @job_args.push(args)
21
+ end
22
+ def self.instance
23
+ @checker ||= self.new
24
+ end
25
+ def self.clear
26
+ @checker = nil
27
+ end
28
+ end
29
+
30
+ class TraceableJob
31
+ include Sidekiq::Worker
32
+ def perform(*args)
33
+ rc = ResultChecker.instance
34
+ rc.push_trace(RequestTracer::Trace.latest.to_h)
35
+ rc.push_job_args(args)
36
+ end
37
+ end
38
+
39
+ class ThreadSpawningMiddleware
40
+ def call(worker_instance, msg, queue, &blk)
41
+ result = nil
42
+ Thread.new { result = blk.call }.join
43
+ result
44
+ end
45
+ end
46
+
47
+ before(:all) do
48
+ Sidekiq::Testing.inline!
49
+ end
50
+
51
+ let(:result_checker) { ResultChecker.instance }
52
+ let(:trace) { RequestTracer::Trace.create }
53
+
54
+ before do
55
+ Sidekiq::Worker.clear_all
56
+ RequestTracer::Trace.clear
57
+ ResultChecker.clear
58
+ end
59
+
60
+ after do
61
+ Sidekiq::Testing.server_middleware {|chn| chn.clear }
62
+ Sidekiq.configure_client {|cfg| cfg.client_middleware {|chn| chn.clear } }
63
+ end
64
+
65
+ context "when asynchronously calling a job with correctly setup middleware" do
66
+ before do
67
+ RequestTracer.integrate_with(:sidekiq)
68
+ Sidekiq::Testing.server_middleware do |chain|
69
+ chain.add ThreadSpawningMiddleware
70
+ chain.add RequestTracer::Integration::SidekiqHandler::ServerMiddleware
71
+ end
72
+ end
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
76
+ TraceableJob.perform_async('foo')
77
+ expect(result_checker.traces).to eq([trace.to_h])
78
+ end
79
+ end
80
+ it "calls the job with the originally given parameters" do
81
+ TraceableJob.perform_async(a_string: "bar", a_number: 12)
82
+ expect(result_checker.job_args).to eq([[{"a_string" => "bar", "a_number" => 12}]])
83
+ end
84
+ end
85
+ context "when asynchronously calling a job with missing server middleware" do
86
+ before do
87
+ RequestTracer.integrate_with(:sidekiq)
88
+ Sidekiq::Testing.server_middleware do |chain|
89
+ chain.add ThreadSpawningMiddleware
90
+ end
91
+ end
92
+ context "when there is an existing trace" do
93
+ before { RequestTracer::Trace.push trace.to_h }
94
+ it "passes the trace from the main process to the worker and records the worker" do
95
+ TraceableJob.perform_async('foo')
96
+ expect(result_checker.traces).to eq([{}])
97
+ end
98
+ end
99
+ end
100
+ context "when asynchronously calling a job with missing client middleware" do
101
+ before do
102
+ Sidekiq::Testing.server_middleware do |chain|
103
+ chain.add ThreadSpawningMiddleware
104
+ chain.add RequestTracer::Integration::SidekiqHandler::ServerMiddleware
105
+ end
106
+ end
107
+ context "when there is an existing trace" do
108
+ before { RequestTracer::Trace.push trace.to_h }
109
+ it "passes the trace from the main process to the worker and records the worker" do
110
+ TraceableJob.perform_async('foo')
111
+ expect(result_checker.traces).to eq([{}])
112
+ end
113
+ end
114
+ end
115
+ 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.5.8
4
+ version: 0.6.1
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-22 00:00:00.000000000 Z
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sidekiq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -213,12 +227,14 @@ files:
213
227
  - lib/request_tracer/integration/base.rb
214
228
  - lib/request_tracer/integration/rack_handler.rb
215
229
  - lib/request_tracer/integration/rest_client_handler.rb
230
+ - lib/request_tracer/integration/sidekiq_handler.rb
216
231
  - lib/request_tracer/trace.rb
217
232
  - lib/request_tracer/version.rb
218
233
  - request-tracer.gemspec
219
234
  - spec/integration/integration_spec.rb
220
235
  - spec/lib/request_tracer/integration/rack_handler_spec.rb
221
236
  - spec/lib/request_tracer/integration/rest_client_handler_spec.rb
237
+ - spec/lib/request_tracer/integration/sidekiq_handler_spec.rb
222
238
  - spec/lib/request_tracer/trace_spec.rb
223
239
  - spec/spec_helper.rb
224
240
  - spec/support/test_app.rb
@@ -251,6 +267,7 @@ test_files:
251
267
  - spec/integration/integration_spec.rb
252
268
  - spec/lib/request_tracer/integration/rack_handler_spec.rb
253
269
  - spec/lib/request_tracer/integration/rest_client_handler_spec.rb
270
+ - spec/lib/request_tracer/integration/sidekiq_handler_spec.rb
254
271
  - spec/lib/request_tracer/trace_spec.rb
255
272
  - spec/spec_helper.rb
256
273
  - spec/support/test_app.rb