instana 1.9.7 → 1.10.0.slimfast

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/instana/agent.rb +19 -19
  3. data/lib/instana/agent/helpers.rb +2 -2
  4. data/lib/instana/agent/tasks.rb +2 -2
  5. data/lib/instana/collectors/gc.rb +1 -1
  6. data/lib/instana/collectors/memory.rb +1 -1
  7. data/lib/instana/collectors/thread.rb +1 -1
  8. data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +1 -1
  9. data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +1 -1
  10. data/lib/instana/helpers.rb +2 -2
  11. data/lib/instana/instrumentation.rb +1 -1
  12. data/lib/instana/instrumentation/excon.rb +8 -5
  13. data/lib/instana/instrumentation/rack.rb +2 -2
  14. data/lib/instana/instrumentation/resque.rb +3 -3
  15. data/lib/instana/tracer.rb +92 -117
  16. data/lib/instana/tracing/processor.rb +18 -133
  17. data/lib/instana/tracing/span.rb +40 -35
  18. data/lib/instana/tracing/span_context.rb +3 -1
  19. data/lib/instana/util.rb +5 -5
  20. data/lib/instana/version.rb +1 -1
  21. data/lib/opentracing.rb +1 -1
  22. data/test/frameworks/rack_test.rb +6 -11
  23. data/test/frameworks/rails/actioncontroller_test.rb +32 -62
  24. data/test/frameworks/rails/actionview5_test.rb +91 -132
  25. data/test/frameworks/rails/activerecord5_test.rb +14 -17
  26. data/test/instrumentation/dalli_test.rb +51 -72
  27. data/test/instrumentation/excon_test.rb +70 -94
  28. data/test/instrumentation/grpc_test.rb +164 -126
  29. data/test/instrumentation/net-http_test.rb +48 -57
  30. data/test/instrumentation/redis_test.rb +4 -6
  31. data/test/instrumentation/resque_test.rb +41 -41
  32. data/test/instrumentation/rest-client_test.rb +25 -31
  33. data/test/instrumentation/sidekiq-client_test.rb +12 -20
  34. data/test/instrumentation/sidekiq-worker_test.rb +48 -63
  35. data/test/jobs/resque_error_job.rb +7 -1
  36. data/test/jobs/resque_fast_job.rb +7 -1
  37. data/test/servers/sidekiq/worker.rb +1 -3
  38. data/test/test_helper.rb +58 -0
  39. data/test/tracing/custom_test.rb +11 -19
  40. data/test/tracing/opentracing_test.rb +48 -156
  41. data/test/tracing/trace_test.rb +67 -67
  42. data/test/tracing/tracer_async_test.rb +75 -175
  43. data/test/tracing/tracer_test.rb +75 -75
  44. metadata +4 -5
  45. data/lib/instana/tracing/trace.rb +0 -316
@@ -22,24 +22,19 @@ class NetHTTPTest < Minitest::Test
22
22
  end
23
23
  end
24
24
 
25
- assert_equal 2, ::Instana.processor.queue_count
25
+ spans = ::Instana.processor.queued_spans
26
+ assert_equal 3, spans.length
26
27
 
27
- traces = Instana.processor.queued_traces
28
- rs_trace = traces[0]
29
- http_trace = traces[1]
30
-
31
- # Net::HTTP trace validation
32
- assert_equal 2, http_trace.spans.length
33
- spans = http_trace.spans.to_a
34
- first_span = spans[0]
35
- second_span = spans[1]
28
+ rs_span = find_first_span_by_name(spans, :rack)
29
+ first_span = find_first_span_by_name(spans, :'net-http-test')
30
+ second_span = find_first_span_by_name(spans, :'net-http')
36
31
 
37
32
  # Span name validation
38
33
  assert_equal :sdk, first_span[:n]
39
34
  assert_equal :'net-http', second_span[:n]
40
35
 
41
36
  # first_span is the parent of second_span
42
- assert_equal first_span.id, second_span[:p]
37
+ assert_equal first_span[:s], second_span[:p]
43
38
 
44
39
  # data keys/values
45
40
  refute_nil second_span.key?(:data)
@@ -48,14 +43,12 @@ class NetHTTPTest < Minitest::Test
48
43
  assert_equal "200", second_span[:data][:http][:status]
49
44
  assert !second_span.key?(:stack)
50
45
 
51
- # Rack server trace validation
52
- assert_equal 1, rs_trace.spans.length
53
- rs_span = rs_trace.spans.to_a[0]
54
-
55
46
  # Rack server trace should have the same trace ID
56
- assert_equal http_trace.id, rs_span[:t].to_i
47
+ assert_equal rs_span[:t], first_span[:t]
48
+ assert_equal first_span[:t], second_span[:t]
49
+
57
50
  # Rack server trace should have net-http has parent span
58
- assert_equal second_span.id, rs_span[:p].to_i
51
+ assert_equal second_span[:s], rs_span[:p]
59
52
 
60
53
  WebMock.disable_net_connect!
61
54
  end
@@ -70,40 +63,33 @@ class NetHTTPTest < Minitest::Test
70
63
  response = http.request(Net::HTTP::Post.new("/"))
71
64
  end
72
65
 
73
- assert_equal 2, ::Instana.processor.queue_count
66
+ spans = ::Instana.processor.queued_spans
67
+ assert_equal 3, spans.length
74
68
 
75
- traces = Instana.processor.queued_traces
76
- rs_trace = traces[0]
77
- http_trace = traces[1]
78
-
79
- # Net::HTTP trace validation
80
- assert_equal 2, http_trace.spans.length
81
- spans = http_trace.spans.to_a
82
- first_span = spans[0]
83
- second_span = spans[1]
69
+ rack_span = find_first_span_by_name(spans, :rack)
70
+ sdk_span = find_first_span_by_name(spans, :'net-http-test')
71
+ http_span = find_first_span_by_name(spans, :'net-http')
84
72
 
85
73
  # Span name validation
86
- assert_equal :sdk, first_span[:n]
87
- assert_equal :'net-http', second_span[:n]
74
+ assert_equal :sdk, sdk_span[:n]
75
+ assert_equal :'net-http', http_span[:n]
88
76
 
89
77
  # first_span is the parent of second_span
90
- assert_equal first_span.id, second_span[:p]
78
+ assert_equal sdk_span[:s], http_span[:p]
91
79
 
92
80
  # data keys/values
93
- refute_nil second_span.key?(:data)
94
- refute_nil second_span[:data].key?(:http)
95
- assert_equal "http://127.0.0.1:6511/", second_span[:data][:http][:url]
96
- assert_equal "200", second_span[:data][:http][:status]
97
- assert !second_span.key?(:stack)
98
-
99
- # Rack server trace validation
100
- assert_equal 1, rs_trace.spans.length
101
- rs_span = rs_trace.spans.to_a[0]
81
+ refute_nil http_span.key?(:data)
82
+ refute_nil http_span[:data].key?(:http)
83
+ assert_equal "http://127.0.0.1:6511/", http_span[:data][:http][:url]
84
+ assert_equal "200", http_span[:data][:http][:status]
85
+ assert !http_span.key?(:stack)
102
86
 
103
87
  # Rack server trace should have the same trace ID
104
- assert_equal http_trace.id, rs_span[:t].to_i
88
+ assert_equal rack_span[:t], sdk_span[:t]
89
+ assert_equal sdk_span[:t], http_span[:t]
90
+
105
91
  # Rack server trace should have net-http has parent span
106
- assert_equal second_span.id, rs_span[:p].to_i
92
+ assert_equal http_span[:s], rack_span[:p]
107
93
 
108
94
  WebMock.disable_net_connect!
109
95
  end
@@ -121,16 +107,15 @@ class NetHTTPTest < Minitest::Test
121
107
  nil
122
108
  end
123
109
 
124
- traces = Instana.processor.queued_traces
125
- assert_equal 1, traces.length
126
- t = traces[0]
127
- assert_equal 1, t.spans.count
128
- assert t.has_error?
129
- spans = t.spans.to_a
130
- first_span = spans[0]
110
+ spans = ::Instana.processor.queued_spans
111
+ assert_equal 1, spans.length
112
+
113
+ first_span = spans.first
131
114
 
132
- assert_equal :'net-http-error-test', first_span.name
133
- assert first_span.custom?
115
+ assert_equal :sdk, first_span[:n]
116
+ assert_equal :'net-http-error-test', first_span[:data][:sdk][:name]
117
+ assert_equal true, first_span[:error]
118
+ assert_equal 1, first_span[:ec]
134
119
  ts_key = first_span[:data][:sdk][:custom][:logs].keys.first
135
120
  assert first_span[:data][:sdk][:custom][:logs].key?(ts_key)
136
121
  assert first_span[:data][:sdk][:custom][:logs][ts_key].key?(:event)
@@ -149,20 +134,26 @@ class NetHTTPTest < Minitest::Test
149
134
  response = http.request(Net::HTTP::Get.new("/error"))
150
135
  end
151
136
 
152
- traces = Instana.processor.queued_traces
153
- assert_equal 2, traces.length
137
+ spans = ::Instana.processor.queued_spans
138
+ assert_equal 3, spans.length
139
+
140
+ rack_span = find_first_span_by_name(spans, :rack)
141
+ sdk_span = find_first_span_by_name(spans, :'net-http-error-test')
142
+ http_span = find_first_span_by_name(spans, :'net-http')
154
143
 
155
- request_trace = traces[1]
156
- assert_equal 2, request_trace.spans.length
157
- assert request_trace.has_error?
158
- http_span = request_trace.spans.to_a[1]
144
+ assert_equal :sdk, sdk_span[:n]
145
+ assert_equal :'net-http-error-test', sdk_span[:data][:sdk][:name]
146
+ assert_equal nil, sdk_span[:error]
147
+ assert_equal nil, sdk_span[:ec]
159
148
 
160
149
  refute_nil http_span.key?(:data)
161
150
  refute_nil http_span[:data].key?(:http)
162
151
  assert_equal "http://127.0.0.1:6511/error", http_span[:data][:http][:url]
163
152
  assert_equal "500", http_span[:data][:http][:status]
164
- assert_equal :'net-http', http_span.name
153
+ assert_equal :'net-http', http_span[:n]
165
154
  assert !http_span.key?(:stack)
155
+ assert_equal true, http_span[:error]
156
+ assert_equal 1, http_span[:ec]
166
157
 
167
158
  WebMock.disable_net_connect!
168
159
  end
@@ -94,14 +94,12 @@ class RedisTest < Minitest::Test
94
94
  end
95
95
 
96
96
  def assert_redis_trace(command, with_error: nil)
97
- assert_equal 1, ::Instana.processor.queue_count
98
- trace = ::Instana.processor.queued_traces.first
99
-
100
- assert_equal 2, trace.spans.length
101
- first_span, second_span = trace.spans.to_a
97
+ spans = ::Instana.processor.queued_spans
98
+ assert_equal 2, spans.length
99
+ first_span, second_span = spans.to_a.reverse
102
100
 
103
101
  # first_span is the parent of second_span
104
- assert_equal first_span.id, second_span[:p]
102
+ assert_equal first_span[:s], second_span[:p]
105
103
  assert_equal :sdk, first_span[:n]
106
104
  assert_equal :redis, second_span[:n]
107
105
 
@@ -5,6 +5,8 @@ require 'resque'
5
5
 
6
6
  if ENV.key?('REDIS_URL')
7
7
  ::Resque.redis = ENV['REDIS_URL']
8
+ elsif ENV.key?('I_REDIS_URL')
9
+ ::Resque.redis = ENV['I_REDIS_URL']
8
10
  else
9
11
  ::Resque.redis = 'localhost:6379'
10
12
  end
@@ -25,20 +27,21 @@ class ResqueClientTest < Minitest::Test
25
27
  ::Resque.enqueue(FastJob)
26
28
  end
27
29
 
28
- traces = Instana.processor.queued_traces
29
- assert_equal 1, traces.length
30
+ spans = ::Instana.processor.queued_spans
31
+ assert_equal 3, spans.length
30
32
 
31
- spans = traces[0].spans.to_a
32
- assert_equal 3, spans.count
33
+ sdk_span = find_first_span_by_name(spans, :'resque-client_test')
34
+ resque_span = find_first_span_by_name(spans, :'resque-client')
35
+ redis_span = find_first_span_by_name(spans, :redis)
33
36
 
34
- assert_equal :'resque-client_test', spans[0][:data][:sdk][:name]
37
+ assert_equal :'resque-client_test', sdk_span[:data][:sdk][:name]
35
38
 
36
- assert_equal :"resque-client", spans[1][:n]
37
- assert_equal "FastJob", spans[1][:data][:'resque-client'][:job]
38
- assert_equal :critical, spans[1][:data][:'resque-client'][:queue]
39
- assert_equal false, spans[1][:data][:'resque-client'].key?(:error)
39
+ assert_equal :"resque-client", resque_span[:n]
40
+ assert_equal "FastJob", resque_span[:data][:'resque-client'][:job]
41
+ assert_equal :critical, resque_span[:data][:'resque-client'][:queue]
42
+ assert_equal false, resque_span[:data][:'resque-client'].key?(:error)
40
43
 
41
- assert_equal :redis, spans[2][:n]
44
+ assert_equal :redis, redis_span[:n]
42
45
  end
43
46
 
44
47
  def test_enqueue_to
@@ -46,18 +49,19 @@ class ResqueClientTest < Minitest::Test
46
49
  ::Resque.enqueue_to(:critical, FastJob)
47
50
  end
48
51
 
49
- traces = Instana.processor.queued_traces
50
- assert_equal 1, traces.length
52
+ spans = ::Instana.processor.queued_spans
53
+ assert_equal 3, spans.length
51
54
 
52
- spans = traces[0].spans.to_a
53
- assert_equal 3, spans.count
55
+ sdk_span = find_first_span_by_name(spans, :'resque-client_test')
56
+ resque_span = find_first_span_by_name(spans, :'resque-client')
57
+ redis_span = find_first_span_by_name(spans, :redis)
54
58
 
55
- assert_equal :'resque-client_test', spans[0][:data][:sdk][:name]
56
- assert_equal :"resque-client", spans[1][:n]
57
- assert_equal "FastJob", spans[1][:data][:'resque-client'][:job]
58
- assert_equal :critical, spans[1][:data][:'resque-client'][:queue]
59
- assert_equal false, spans[1][:data][:'resque-client'].key?(:error)
60
- assert_equal :redis, spans[2][:n]
59
+ assert_equal :'resque-client_test', sdk_span[:data][:sdk][:name]
60
+ assert_equal :"resque-client", resque_span[:n]
61
+ assert_equal "FastJob", resque_span[:data][:'resque-client'][:job]
62
+ assert_equal :critical, resque_span[:data][:'resque-client'][:queue]
63
+ assert_equal false, resque_span[:data][:'resque-client'].key?(:error)
64
+ assert_equal :redis, redis_span[:n]
61
65
  end
62
66
 
63
67
  def test_dequeue
@@ -65,33 +69,31 @@ class ResqueClientTest < Minitest::Test
65
69
  ::Resque.dequeue(FastJob, { :generate => :farfalla })
66
70
  end
67
71
 
68
- traces = Instana.processor.queued_traces
69
- assert_equal 1, traces.length
72
+ spans = ::Instana.processor.queued_spans
73
+ assert_equal 3, spans.length
70
74
 
71
- spans = traces[0].spans.to_a
72
- assert_equal 3, spans.count
75
+ sdk_span = find_first_span_by_name(spans, :'resque-client_test')
76
+ resque_span = find_first_span_by_name(spans, :'resque-client')
77
+ redis_span = find_first_span_by_name(spans, :redis)
73
78
 
74
- assert_equal :'resque-client_test', spans[0][:data][:sdk][:name]
79
+ assert_equal :'resque-client_test', sdk_span[:data][:sdk][:name]
75
80
  assert_equal :"resque-client", spans[1][:n]
76
- assert_equal "FastJob", spans[1][:data][:'resque-client'][:job]
77
- assert_equal :critical, spans[1][:data][:'resque-client'][:queue]
78
- assert_equal false, spans[1][:data][:'resque-client'].key?(:error)
79
- assert_equal :redis, spans[2][:n]
81
+ assert_equal "FastJob", resque_span[:data][:'resque-client'][:job]
82
+ assert_equal :critical, resque_span[:data][:'resque-client'][:queue]
83
+ assert_equal false, resque_span[:data][:'resque-client'].key?(:error)
84
+ assert_equal :redis, redis_span[:n]
80
85
  end
81
86
 
82
87
  def test_worker_job
83
88
  Resque::Job.create(:critical, FastJob)
84
89
  @worker.work(0)
85
90
 
86
- traces = Instana.processor.queued_traces
87
- assert_equal 1, traces.length
88
-
89
- spans = traces[0].spans.to_a
90
- assert_equal 3, spans.count
91
+ spans = ::Instana.processor.queued_spans
92
+ assert_equal 3, spans.length
91
93
 
92
- resque_span = spans[0]
94
+ resque_span = spans[2]
93
95
  redis1_span = spans[1]
94
- redis2_span = spans[2]
96
+ redis2_span = spans[0]
95
97
 
96
98
  assert_equal :'resque-worker', resque_span[:n]
97
99
  assert_equal false, resque_span.key?(:error)
@@ -110,12 +112,10 @@ class ResqueClientTest < Minitest::Test
110
112
  Resque::Job.create(:critical, ErrorJob)
111
113
  @worker.work(0)
112
114
 
113
- traces = Instana.processor.queued_traces
114
- assert_equal 1, traces.length
115
+ spans = ::Instana.processor.queued_spans
116
+ assert_equal 5, spans.length
115
117
 
116
- spans = traces[0].spans.to_a
117
- resque_span = spans[0]
118
- assert_equal 5, spans.count
118
+ resque_span = find_first_span_by_name(spans, :'resque-worker')
119
119
 
120
120
  assert_equal :'resque-worker', resque_span[:n]
121
121
  assert_equal true, resque_span.key?(:error)
@@ -17,44 +17,38 @@ class RestClientTest < Minitest::Test
17
17
  RestClient.get url
18
18
  end
19
19
 
20
- assert_equal 2, ::Instana.processor.queue_count
20
+ spans = ::Instana.processor.queued_spans
21
+ assert_equal 4, spans.length
21
22
 
22
- traces = Instana.processor.queued_traces
23
- rs_trace = traces[0]
24
- http_trace = traces[1]
23
+ rack_span = find_first_span_by_name(spans, :rack)
24
+ sdk_span = find_first_span_by_name(spans, :'restclient-test')
25
+ rest_span = find_first_span_by_name(spans, :'rest-client')
26
+ net_span = find_first_span_by_name(spans, :'net-http')
25
27
 
26
- # RestClient trace validation
27
- assert_equal 3, http_trace.spans.length
28
- spans = http_trace.spans.to_a
29
- first_span = spans[0]
30
- second_span = spans[1]
31
- third_span = spans[2]
28
+ validate_sdk_span(sdk_span, {:name => :'restclient-test', :type => :intermediate})
29
+ validate_sdk_span(rest_span, {:name => :'rest-client', :type => :intermediate})
32
30
 
33
31
  # Span name validation
34
- assert first_span.custom?
35
- assert_equal :"restclient-test", first_span.name
36
- assert_equal :"rest-client", second_span.name
37
- assert_equal :"net-http", third_span.name
32
+ assert_equal :rack, rack_span[:n]
33
+ assert_equal :sdk, sdk_span[:n]
34
+ assert_equal :sdk, rest_span[:n]
35
+ assert_equal :"net-http", net_span[:n]
38
36
 
39
- # first_span is the parent of second_span
40
- assert_equal first_span.id, second_span[:p]
41
- # second_span is parent of third_span
42
- assert_equal second_span.id, third_span[:p]
37
+ # Trace IDs and relationships
38
+ trace_id = sdk_span[:t]
39
+ assert_equal trace_id, rest_span[:t]
40
+ assert_equal trace_id, net_span[:t]
41
+ assert_equal trace_id, rack_span[:t]
42
+
43
+ assert_equal sdk_span[:s], rest_span[:p]
44
+ assert_equal rest_span[:s], net_span[:p]
45
+ assert_equal net_span[:s], rack_span[:p]
43
46
 
44
47
  # data keys/values
45
- refute_nil third_span.key?(:data)
46
- refute_nil third_span[:data].key?(:http)
47
- assert_equal "http://127.0.0.1:6511/", third_span[:data][:http][:url]
48
- assert_equal "200", third_span[:data][:http][:status]
49
-
50
- # Rack server trace validation
51
- assert_equal 1, rs_trace.spans.length
52
- rs_span = rs_trace.spans.to_a[0]
53
-
54
- # Rack server trace should have the same trace ID
55
- assert_equal http_trace.id, rs_span[:t].to_i
56
- # Rack server trace should have net-http has parent span
57
- assert_equal third_span.id, rs_span[:p].to_i
48
+ refute_nil net_span.key?(:data)
49
+ refute_nil net_span[:data].key?(:http)
50
+ assert_equal "http://127.0.0.1:6511/", net_span[:data][:http][:url]
51
+ assert_equal "200", net_span[:data][:http][:status]
58
52
 
59
53
  WebMock.disable_net_connect!
60
54
  end
@@ -65,18 +65,14 @@ class SidekiqClientTest < Minitest::Test
65
65
  end
66
66
 
67
67
  def assert_normal_trace_recorded(job)
68
- assert_equal 1, ::Instana.processor.queue_count
69
- client_trace = Instana.processor.queued_traces.first
68
+ spans = ::Instana.processor.queued_spans
69
+ assert_equal 2, spans.length
70
70
 
71
- assert_equal 2, client_trace.spans.length
72
- spans = client_trace.spans.to_a
73
- first_span = spans[0]
74
- second_span = spans[1]
71
+ first_span = spans[1]
72
+ second_span = spans[0]
75
73
 
76
- assert_equal :sdk, first_span[:n]
77
- assert_equal :sidekiqtests, first_span[:data][:sdk][:name]
78
-
79
- assert_equal first_span.id, second_span[:p]
74
+ assert_equal first_span[:s], second_span[:p]
75
+ validate_sdk_span(first_span, {:name => :sidekiqtests, :type => :intermediate})
80
76
 
81
77
  assert_equal :'sidekiq-client', second_span[:n]
82
78
  assert_equal 'some_random_queue', second_span[:data][:'sidekiq-client'][:queue]
@@ -86,18 +82,14 @@ class SidekiqClientTest < Minitest::Test
86
82
  end
87
83
 
88
84
  def assert_failure_trace_recorded
89
- assert_equal 1, ::Instana.processor.queue_count
90
- client_trace = Instana.processor.queued_traces.first
91
-
92
- assert_equal 2, client_trace.spans.length
93
- spans = client_trace.spans.to_a
94
- first_span = spans[0]
95
- second_span = spans[1]
85
+ spans = ::Instana.processor.queued_spans
86
+ assert_equal 2, spans.length
96
87
 
97
- assert_equal :sdk, first_span[:n]
98
- assert_equal :sidekiqtests, first_span[:data][:sdk][:name]
88
+ first_span = spans[1]
89
+ second_span = spans[0]
99
90
 
100
- assert_equal first_span.id, second_span[:p]
91
+ assert_equal first_span[:s], second_span[:p]
92
+ validate_sdk_span(first_span, {:name => :sidekiqtests, :type => :intermediate})
101
93
 
102
94
  assert_equal :'sidekiq-client', second_span[:n]
103
95
  assert_equal true, second_span[:error]
@@ -30,8 +30,9 @@ class SidekiqServerTest < Minitest::Test
30
30
  enable_redis_instrumentation
31
31
  sleep 1
32
32
 
33
- assert_equal 1, ::Instana.processor.queue_count
34
- assert_successful_worker_trace(::Instana.processor.queued_traces.first)
33
+ spans = Instana.processor.queued_spans
34
+ worker_span = find_spans_by_name(spans, :'sidekiq-worker').first
35
+ assert_successful_worker_span(worker_span)
35
36
 
36
37
  $sidekiq_mode = :client
37
38
  end
@@ -59,8 +60,10 @@ class SidekiqServerTest < Minitest::Test
59
60
  enable_redis_instrumentation
60
61
 
61
62
  sleep 1
62
- assert_equal 1, ::Instana.processor.queue_count
63
- assert_failed_worker_trace(::Instana.processor.queued_traces.first)
63
+
64
+ spans = Instana.processor.queued_spans
65
+ worker_span = find_spans_by_name(spans, :'sidekiq-worker').first
66
+ assert_failed_worker_span(worker_span)
64
67
 
65
68
  $sidekiq_mode = :client
66
69
  end
@@ -80,15 +83,20 @@ class SidekiqServerTest < Minitest::Test
80
83
  enable_redis_instrumentation
81
84
  end
82
85
  sleep 1
83
- assert_equal 2, ::Instana.processor.queue_count
84
- client_trace, worker_trace = differentiate_trace(
85
- Instana.processor.queued_traces.to_a
86
- )
87
- assert_client_trace(client_trace, ::SidekiqJobOne)
88
- assert_successful_worker_trace(worker_trace)
86
+ spans = Instana.processor.queued_spans
87
+
88
+ sdk_span = find_spans_by_name(spans, :sidekiqtests).first
89
+ validate_sdk_span(sdk_span)
90
+
91
+ client_span = find_spans_by_name(spans, :'sidekiq-client').first
92
+ assert_client_span(client_span, ::SidekiqJobOne)
93
+
94
+ worker_span = find_spans_by_name(spans, :'sidekiq-worker').first
95
+ assert_successful_worker_span(worker_span)
89
96
 
90
97
  # Worker trace and client trace are in the same trace
91
- assert_equal client_trace.spans.first['t'], worker_trace.spans.first['t']
98
+ assert_equal worker_span[:t], client_span[:t]
99
+ assert_equal worker_span[:p], client_span[:s]
92
100
 
93
101
  $sidekiq_mode = :client
94
102
  end
@@ -108,15 +116,21 @@ class SidekiqServerTest < Minitest::Test
108
116
  enable_redis_instrumentation
109
117
  end
110
118
  sleep 1
111
- assert_equal 2, ::Instana.processor.queue_count
112
- client_trace, worker_trace = differentiate_trace(
113
- Instana.processor.queued_traces.to_a
114
- )
115
- assert_client_trace(client_trace, ::SidekiqJobTwo)
116
- assert_failed_worker_trace(worker_trace)
119
+
120
+ spans = Instana.processor.queued_spans
121
+
122
+ sdk_span = find_spans_by_name(spans, :sidekiqtests).first
123
+ validate_sdk_span(sdk_span)
124
+
125
+ client_span = find_spans_by_name(spans, :'sidekiq-client').first
126
+ assert_client_span(client_span, ::SidekiqJobTwo)
127
+
128
+ worker_span = find_spans_by_name(spans, :'sidekiq-worker').first
129
+ assert_failed_worker_span(worker_span)
117
130
 
118
131
  # Worker trace and client trace are in the same trace
119
- assert_equal client_trace.spans.first['t'], worker_trace.spans.first['t']
132
+ assert_equal worker_span[:t], client_span[:t]
133
+ assert_equal worker_span[:p], client_span[:s]
120
134
 
121
135
  $sidekiq_mode = :client
122
136
  end
@@ -132,57 +146,28 @@ class SidekiqServerTest < Minitest::Test
132
146
  end
133
147
  end
134
148
 
135
- def differentiate_trace(traces)
136
- trying_client = traces[0]
137
- trying_server = traces[1]
138
-
139
- try_successfully = trying_client.spans.any? do |span|
140
- span.name == :'sidekiq-client'
141
- end
149
+ def assert_successful_worker_span(worker_span)
150
+ assert_equal :'sidekiq-worker', worker_span[:n]
142
151
 
143
- if try_successfully
144
- [trying_client, trying_server]
145
- else
146
- [trying_server, trying_client]
147
- end
152
+ assert_equal 'important', worker_span[:data][:'sidekiq-worker'][:queue]
153
+ assert_equal 'SidekiqJobOne', worker_span[:data][:'sidekiq-worker'][:job]
154
+ assert_equal false, worker_span[:data][:'sidekiq-worker'][:job_id].nil?
148
155
  end
149
156
 
150
- def assert_successful_worker_trace(worker_trace)
151
- assert_equal 1, worker_trace.spans.length
152
- span = worker_trace.spans.first
157
+ def assert_failed_worker_span(worker_span)
158
+ assert_equal :'sidekiq-worker', worker_span[:n]
153
159
 
154
- assert_equal :'sidekiq-worker', span[:n]
160
+ assert_equal 'important', worker_span[:data][:'sidekiq-worker'][:queue]
161
+ assert_equal 'SidekiqJobTwo', worker_span[:data][:'sidekiq-worker'][:job]
162
+ assert_equal false, worker_span[:data][:'sidekiq-worker'][:job_id].nil?
155
163
 
156
- assert_equal 'important', span[:data][:'sidekiq-worker'][:queue]
157
- assert_equal 'SidekiqJobOne', span[:data][:'sidekiq-worker'][:job]
158
- assert_equal false, span[:data][:'sidekiq-worker'][:job_id].nil?
164
+ assert_equal true, worker_span[:data][:'sidekiq-worker'][:error]
165
+ assert_equal 'Fail to execute the job', worker_span[:data][:log][:message]
159
166
  end
160
167
 
161
- def assert_failed_worker_trace(worker_trace)
162
- assert_equal 1, worker_trace.spans.length
163
- span = worker_trace.spans.first
164
-
165
- assert_equal :'sidekiq-worker', span[:n]
166
-
167
- assert_equal 'important', span[:data][:'sidekiq-worker'][:queue]
168
- assert_equal 'SidekiqJobTwo', span[:data][:'sidekiq-worker'][:job]
169
- assert_equal false, span[:data][:'sidekiq-worker'][:job_id].nil?
170
-
171
- assert_equal true, span[:data][:'sidekiq-worker'][:error]
172
- assert_equal 'Fail to execute the job', span[:data][:log][:message]
173
- end
174
-
175
- def assert_client_trace(client_trace, job)
176
- assert_equal 2, client_trace.spans.length
177
- first_span, second_span = client_trace.spans.to_a
178
-
179
- assert_equal :sdk, first_span[:n]
180
- assert_equal :sidekiqtests, first_span[:data][:sdk][:name]
181
-
182
- assert_equal first_span.id, second_span[:p]
183
-
184
- assert_equal :'sidekiq-client', second_span[:n]
185
- assert_equal 'important', second_span[:data][:'sidekiq-client'][:queue]
186
- assert_equal job.name, second_span[:data][:'sidekiq-client'][:job]
168
+ def assert_client_span(client_span, job)
169
+ assert_equal :'sidekiq-client', client_span[:n]
170
+ assert_equal 'important', client_span[:data][:'sidekiq-client'][:queue]
171
+ assert_equal job.name, client_span[:data][:'sidekiq-client'][:job]
187
172
  end
188
173
  end