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
@@ -5,7 +5,13 @@ class ErrorJob
5
5
  @queue = :critical
6
6
 
7
7
  def self.perform
8
- redis = Redis.new(url: ENV['REDIS_URL'])
8
+ if ENV.key?('REDIS_URL')
9
+ redis = Redis.new(:url => ENV['REDIS_URL'])
10
+ elsif ENV.key?('I_REDIS_URL')
11
+ redis = Redis.new(:url => ENV['I_REDIS_URL'])
12
+ else
13
+ redis = Redis.new(:url => 'localhost:6379')
14
+ end
9
15
 
10
16
  dt = Time.now
11
17
  redis.set('ts', dt)
@@ -5,7 +5,13 @@ class FastJob
5
5
  @queue = :critical
6
6
 
7
7
  def self.perform
8
- redis = Redis.new(url: ENV['REDIS_URL'])
8
+ if ENV.key?('REDIS_URL')
9
+ redis = Redis.new(:url => ENV['REDIS_URL'])
10
+ elsif ENV.key?('I_REDIS_URL')
11
+ redis = Redis.new(:url => ENV['I_REDIS_URL'])
12
+ else
13
+ redis = Redis.new(:url => 'redis://localhost:6379')
14
+ end
9
15
 
10
16
  dt = Time.now
11
17
  redis.set('ts', dt)
@@ -23,7 +23,5 @@ end
23
23
  Minitest.after_run do
24
24
  ::Instana.logger.info "Killing Sidekiq worker"
25
25
  sidekiq_thread[:worker].stop
26
- sleep 2
26
+ sleep 1
27
27
  end
28
-
29
- sleep 5
@@ -85,3 +85,61 @@ def enable_redis_instrumentation
85
85
  alias call_pipeline call_pipeline_with_instana
86
86
  end
87
87
  end
88
+
89
+ def validate_sdk_span(json_span, sdk_hash = {}, errored = false, ec = 1)
90
+ assert_equal :sdk, json_span[:n]
91
+ assert json_span.key?(:k)
92
+ assert json_span.key?(:d)
93
+ assert json_span.key?(:ts)
94
+
95
+ for k,v in sdk_hash
96
+ assert_equal v, json_span[:data][:sdk][k]
97
+ end
98
+
99
+ if errored
100
+ assert_equal true, json_span[:error]
101
+ assert_equal 1, json_span[:ec]
102
+ end
103
+ end
104
+
105
+ def find_spans_by_name(spans, name)
106
+ result = []
107
+ for span in spans
108
+ if span[:n] == :sdk
109
+ if span[:data][:sdk][:name] == name
110
+ result << span
111
+ end
112
+ elsif span[:n] == name
113
+ result << span
114
+ end
115
+ end
116
+ if result.empty?
117
+ raise Exception.new("No SDK spans (#{name}) could be found")
118
+ else
119
+ return result
120
+ end
121
+ end
122
+
123
+ def find_first_span_by_name(spans, name)
124
+ for span in spans
125
+ if span[:n] == :sdk
126
+ if span[:data][:sdk][:name] == name
127
+ return span
128
+ end
129
+ else
130
+ if span[:n] == name
131
+ return span
132
+ end
133
+ end
134
+ end
135
+ raise Exception.new("Span (#{name}) not found")
136
+ end
137
+
138
+ def find_span_by_id(spans, id)
139
+ for span in spans
140
+ if span[:s] == id
141
+ return span
142
+ end
143
+ end
144
+ raise Exception.new("Span with id (#{id}) not found")
145
+ end
@@ -13,13 +13,10 @@ class CustomTracingTest < Minitest::Test
13
13
  ::Instana.tracer.log_end(:custom_trace, {:close_one => 1})
14
14
  assert_equal false, ::Instana.tracer.tracing?
15
15
 
16
- traces = ::Instana.processor.queued_traces
17
- assert_equal 1, traces.length
18
- t = traces.first
19
- assert_equal 1, t.spans.size
20
- assert t.valid?
16
+ spans = ::Instana.processor.queued_spans
17
+ assert_equal 1, spans.length
21
18
 
22
- first_span = t.spans.first
19
+ first_span = spans.first
23
20
  assert_equal :sdk, first_span[:n]
24
21
 
25
22
  assert first_span[:ts].is_a?(Integer)
@@ -33,7 +30,6 @@ class CustomTracingTest < Minitest::Test
33
30
  assert first_span[:data][:sdk][:custom].key?(:tags)
34
31
  assert_equal :custom_trace, first_span[:data][:sdk][:name]
35
32
  assert_equal 1, first_span[:data][:sdk][:custom][:tags][:one]
36
- assert_equal :ruby, first_span[:ta]
37
33
 
38
34
  assert first_span.key?(:f)
39
35
  assert first_span[:f].key?(:e)
@@ -62,13 +58,11 @@ class CustomTracingTest < Minitest::Test
62
58
  ::Instana.tracer.log_end(:rack, {:on_trace_end => 1})
63
59
  assert_equal false, ::Instana.tracer.tracing?
64
60
 
65
- traces = ::Instana.processor.queued_traces
66
- assert_equal 1, traces.length
67
- t = traces.first
68
- assert_equal 2, t.spans.size
69
- assert t.valid?
61
+ spans = ::Instana.processor.queued_spans
62
+ assert_equal 2, spans.length
70
63
 
71
- first_span, second_span = t.spans.to_a
64
+ first_span = find_first_span_by_name(spans, :rack)
65
+ second_span = find_first_span_by_name(spans, :custom_span)
72
66
 
73
67
  assert first_span[:ts].is_a?(Integer)
74
68
  assert first_span[:ts] > 0
@@ -121,13 +115,11 @@ class CustomTracingTest < Minitest::Test
121
115
  ::Instana.tracer.log_end(:rack, {:on_trace_end => 1})
122
116
  assert_equal false, ::Instana.tracer.tracing?
123
117
 
124
- traces = ::Instana.processor.queued_traces
125
- assert_equal 1, traces.length
126
- t = traces.first
127
- assert_equal 2, t.spans.size
128
- assert t.valid?
118
+ spans = ::Instana.processor.queued_spans
119
+ assert_equal 2, spans.length
129
120
 
130
- first_span, second_span = t.spans.to_a
121
+ first_span = find_first_span_by_name(spans, :rack)
122
+ second_span = find_first_span_by_name(spans, :custom_span)
131
123
 
132
124
  assert first_span[:ts].is_a?(Integer)
133
125
  assert first_span[:ts] > 0
@@ -79,17 +79,14 @@ class OpenTracerTest < Minitest::Test
79
79
  get '/mrlobster'
80
80
  assert last_response.ok?
81
81
 
82
- traces = ::Instana.processor.queued_traces
83
- assert_equal 1, traces.length
82
+ spans = ::Instana.processor.queued_spans
83
+ assert_equal 3, spans.length
84
84
 
85
- trace = traces[0]
86
- assert trace.valid?
85
+ first_span = find_first_span_by_name(spans, :rack)
86
+ second_span = find_first_span_by_name(spans, :otrack1)
87
+ third_span = find_first_span_by_name(spans, :otrack2)
87
88
 
88
- # Span validation
89
- assert_equal 3, trace.spans.length
90
- first_span, second_span, third_span = trace.spans.to_a
91
-
92
- assert_equal :rack, first_span.name
89
+ assert_equal :rack, first_span[:n]
93
90
  assert first_span[:ts].is_a?(Integer)
94
91
  assert first_span[:ts] > 0
95
92
  assert first_span[:d].is_a?(Integer)
@@ -100,21 +97,18 @@ class OpenTracerTest < Minitest::Test
100
97
  assert_equal "/mrlobster", first_span[:data][:http][:url]
101
98
  assert_equal 200, first_span[:data][:http][:status]
102
99
  assert_equal 'example.org', first_span[:data][:http][:host]
103
- assert_equal :otrack1, second_span.name
100
+ assert_equal :otrack1, second_span[:data][:sdk][:name]
104
101
  assert second_span.key?(:data)
105
102
  assert second_span[:data].key?(:sdk)
106
103
  assert second_span[:data][:sdk].key?(:name)
107
- assert_equal :otrack2, third_span.name
104
+ assert_equal :otrack2, third_span[:data][:sdk][:name]
108
105
  assert third_span.key?(:data)
109
106
  assert third_span[:data].key?(:sdk)
110
107
  assert third_span[:data][:sdk].key?(:name)
111
108
 
112
109
  # ID Validation
113
- assert_equal trace.id, first_span[:t]
114
- assert_equal trace.id, third_span[:t]
115
-
116
- # Linkage
117
- assert_equal second_span[:s], third_span[:p]
110
+ refute_equal first_span[:t], second_span[:t]
111
+ refute_equal second_span[:t], third_span[:t]
118
112
  end
119
113
 
120
114
  def test_get_with_inject_extract
@@ -129,19 +123,14 @@ class OpenTracerTest < Minitest::Test
129
123
  get '/mrlobster'
130
124
  assert last_response.ok?
131
125
 
132
- traces = ::Instana.processor.queued_traces
133
- assert_equal 1, traces.length
134
-
135
- trace = traces[0]
136
- assert trace.valid?
126
+ spans = ::Instana.processor.queued_spans
137
127
 
138
- # Span validation
139
- assert_equal 3, trace.spans.length
140
- first_span = trace.spans.to_a.first
128
+ assert_equal 3, spans.length
129
+ first_span = find_first_span_by_name(spans, :rack)
141
130
 
142
131
  # Make sure context was picked up and continued in the resulting
143
132
  # trace
144
- assert_equal trace_id, trace.id
133
+ assert_equal trace_id, first_span[:t]
145
134
  assert_equal span_id, first_span[:p]
146
135
  end
147
136
 
@@ -150,7 +139,6 @@ class OpenTracerTest < Minitest::Test
150
139
  span = OpenTracing.start_span('my_app_entry')
151
140
 
152
141
  assert span.is_a?(::Instana::Span)
153
- assert_equal :my_app_entry, OpenTracing.current_trace.current_span.name
154
142
 
155
143
  span.set_tag(:tag_integer, 1234)
156
144
  span.set_tag(:tag_boolean, true)
@@ -172,7 +160,6 @@ class OpenTracerTest < Minitest::Test
172
160
  span = OpenTracing.start_span('my_app_entry', :start_time => now)
173
161
 
174
162
  assert span.is_a?(::Instana::Span)
175
- assert_equal :my_app_entry, OpenTracing.current_trace.current_span.name
176
163
 
177
164
  span.set_tag(:tag_integer, 1234)
178
165
  span.set_tag(:tag_boolean, true)
@@ -196,28 +183,27 @@ class OpenTracerTest < Minitest::Test
196
183
  span = OpenTracing.start_span('my_app_entry')
197
184
 
198
185
  assert span.is_a?(::Instana::Span)
199
- assert_equal :my_app_entry, OpenTracing.current_trace.current_span.name
200
186
 
201
187
  span.set_tag(:'span.kind', :server)
202
188
  assert_equal :entry, span[:data][:sdk][:type]
203
- assert_equal :entry, span[:k]
189
+ assert_equal 1, span[:k]
204
190
 
205
191
  span.set_tag(:'span.kind', :consumer)
206
192
  assert_equal :entry, span[:data][:sdk][:type]
207
- assert_equal :entry, span[:k]
193
+ assert_equal 1, span[:k]
208
194
 
209
195
  span.set_tag(:'span.kind', :client)
210
196
  assert_equal :exit, span[:data][:sdk][:type]
211
- assert_equal :exit, span[:k]
197
+ assert_equal 2, span[:k]
212
198
 
213
199
  span.set_tag(:'span.kind', :producer)
214
200
  assert_equal :exit, span[:data][:sdk][:type]
215
- assert_equal :exit, span[:k]
201
+ assert_equal 2, span[:k]
216
202
 
217
203
  span[:data][:sdk].delete(:type)
218
204
  span.set_tag(:'span.kind', :blah)
219
205
  assert_equal :intermediate, span[:data][:sdk][:type]
220
- assert_equal :intermediate, span[:k]
206
+ assert_equal 3, span[:k]
221
207
  assert_equal :blah, span[:data][:sdk][:custom][:tags][:'span.kind']
222
208
 
223
209
  span.finish
@@ -270,53 +256,19 @@ class OpenTracerTest < Minitest::Test
270
256
  ac_span.finish
271
257
  entry_span.finish
272
258
 
273
- traces = ::Instana.processor.queued_traces
274
-
275
- assert_equal 1, traces.length
276
-
277
- trace = traces.first
278
- first_span, second_span, third_span = trace.spans.to_a
279
-
280
- assert_equal 3, trace.spans.length
281
- assert trace.valid?
282
-
283
- # IDs
284
- assert_equal trace.id, first_span[:t]
285
- assert_equal trace.id, second_span[:t]
286
- assert_equal trace.id, third_span[:t]
287
-
288
- # Linkage
289
- assert first_span.is_root?
290
- assert_equal first_span[:s], second_span[:p]
291
- assert_equal second_span[:s], third_span[:p]
292
- end
293
-
294
- def test_start_span_with_nested_spans
295
- clear_all!
296
- entry_span = OpenTracing.start_span(:rack)
297
- ac_span = OpenTracing.start_span(:action_controller)
298
- av_span = OpenTracing.start_span(:action_view)
299
- sleep 0.1
300
- av_span.finish
301
- ac_span.finish
302
- entry_span.finish
303
-
304
- traces = ::Instana.processor.queued_traces
305
-
306
- assert_equal 1, traces.length
307
- trace = traces.first
308
- assert trace.valid?
309
- assert_equal 3, trace.spans.length
259
+ spans = ::Instana.processor.queued_spans
260
+ assert_equal 3, spans.length
310
261
 
311
- first_span, second_span, third_span = trace.spans.to_a
262
+ first_span = find_first_span_by_name(spans, :rack)
263
+ second_span = find_first_span_by_name(spans, :action_controller)
264
+ third_span = find_first_span_by_name(spans, :action_view)
312
265
 
313
266
  # IDs
314
- assert_equal trace.id, first_span[:t]
315
- assert_equal trace.id, second_span[:t]
316
- assert_equal trace.id, third_span[:t]
267
+ assert_equal first_span[:t], second_span[:t]
268
+ assert_equal second_span[:t], third_span[:t]
317
269
 
318
270
  # Linkage
319
- assert first_span.is_root?
271
+ assert first_span[:p].nil?
320
272
  assert_equal first_span[:s], second_span[:p]
321
273
  assert_equal second_span[:s], third_span[:p]
322
274
  end
@@ -324,37 +276,34 @@ class OpenTracerTest < Minitest::Test
324
276
  def test_nested_spans_with_baggage
325
277
  clear_all!
326
278
  entry_span = OpenTracing.start_span(:rack)
327
- ac_span = OpenTracing.start_span(:action_controller)
279
+ ac_span = OpenTracing.start_span(:action_controller, child_of: entry_span)
328
280
  ac_span.set_baggage_item(:my_bag, 1)
329
- av_span = OpenTracing.start_span(:action_view)
281
+ av_span = OpenTracing.start_span(:action_view, child_of: ac_span)
330
282
  sleep 0.1
331
283
  av_span.finish
332
284
  ac_span.finish
333
285
  entry_span.finish
334
286
 
335
- traces = ::Instana.processor.queued_traces
336
-
337
- assert_equal 1, traces.length
338
- trace = traces.first
339
- assert trace.valid?
340
- assert_equal 3, trace.spans.length
287
+ spans = ::Instana.processor.queued_spans
288
+ assert_equal 3, spans.length
341
289
 
342
- first_span, second_span, third_span = trace.spans.to_a
290
+ first_span = find_first_span_by_name(spans, :rack)
291
+ second_span = find_first_span_by_name(spans, :action_controller)
292
+ third_span = find_first_span_by_name(spans, :action_view)
343
293
 
344
294
  # IDs
345
- assert_equal trace.id, first_span[:t]
346
- assert_equal trace.id, second_span[:t]
347
- assert_equal trace.id, third_span[:t]
295
+ assert_equal first_span[:t], second_span[:t]
296
+ assert_equal second_span[:t], third_span[:t]
348
297
 
349
298
  # Linkage
350
- assert first_span.is_root?
299
+ assert first_span[:p].nil?
351
300
  assert_equal first_span[:s], second_span[:p]
352
301
  assert_equal second_span[:s], third_span[:p]
353
302
 
354
303
  # Every span should have baggage
355
- assert_equal nil, first_span.get_baggage_item(:my_bag)
356
- assert_equal 1, second_span.get_baggage_item(:my_bag)
357
- assert_equal 1, third_span.get_baggage_item(:my_bag)
304
+ assert_equal(nil, entry_span.context.baggage)
305
+ assert_equal({:my_bag=>1}, ac_span.context.baggage)
306
+ assert_equal({:my_bag=>1}, av_span.context.baggage)
358
307
  end
359
308
 
360
309
  def test_context_should_carry_baggage
@@ -363,81 +312,24 @@ class OpenTracerTest < Minitest::Test
363
312
  entry_span = OpenTracing.start_span(:rack)
364
313
  entry_span_context = entry_span.context
365
314
 
366
- ac_span = OpenTracing.start_span(:action_controller)
315
+ ac_span = OpenTracing.start_span(:action_controller, child_of: entry_span)
367
316
  ac_span.set_baggage_item(:my_bag, 1)
368
317
  ac_span_context = ac_span.context
369
318
 
370
- av_span = OpenTracing.start_span(:action_view)
319
+ av_span = OpenTracing.start_span(:action_view, child_of: entry_span)
371
320
  av_span_context = av_span.context
372
321
 
373
322
  sleep 0.1
374
- av_span.finish
375
- ac_span.finish
376
- entry_span.finish
377
-
378
- traces = ::Instana.processor.queued_traces
379
-
380
- assert_equal 1, traces.length
381
- trace = traces.first
382
- assert trace.valid?
383
- assert_equal 3, trace.spans.length
384
323
 
385
- assert_equal nil, entry_span_context.baggage[:my_bag]
386
- assert_equal 1, ac_span_context.baggage[:my_bag]
387
- assert_equal 1, av_span_context.baggage[:my_bag]
388
- end
389
-
390
- def test_baggage_with_complex_data
391
- clear_all!
392
-
393
- entry_span = OpenTracing.start_span(:rack)
394
- entry_span_context = entry_span.context
395
-
396
- ac_span = OpenTracing.start_span(:action_controller)
397
-
398
- ac_span.set_baggage_item(:integer, 1)
399
- ac_span.set_baggage_item(:float, 1.0123948293)
400
- ac_span.set_baggage_item(:hash, { :hash_sublevel => "blah",
401
- :another => {} })
402
- ac_span_context = ac_span.context
403
-
404
- av_span = OpenTracing.start_span(:action_view)
405
- av_span_context = av_span.context
406
-
407
- sleep 0.1
408
324
  av_span.finish
409
325
  ac_span.finish
410
326
  entry_span.finish
411
327
 
412
- traces = ::Instana.processor.queued_traces
413
-
414
- assert_equal 1, traces.length
415
- trace = traces.first
416
- assert trace.valid?
417
- assert_equal 3, trace.spans.length
418
-
419
- # Context
420
- assert_equal true, entry_span_context.baggage.empty?
421
- assert_equal true, entry_span.baggage.empty?
422
-
423
- assert_equal 1, ac_span_context.baggage[:integer]
424
- assert_equal 1.0123948293, ac_span_context.baggage[:float]
425
- assert_equal true, ac_span_context.baggage[:hash][:another].empty?
426
- assert_equal "blah", ac_span_context.baggage[:hash][:hash_sublevel]
427
- assert_equal 1, av_span_context.baggage[:integer]
428
- assert_equal 1.0123948293, av_span_context.baggage[:float]
429
- assert_equal true, av_span_context.baggage[:hash][:another].empty?
430
- assert_equal "blah", av_span_context.baggage[:hash][:hash_sublevel]
431
-
432
- # Spans
433
- assert_equal true, entry_span.baggage.empty?
434
- assert_equal 1, ac_span.baggage[:integer]
435
- assert_equal 1.0123948293, ac_span.baggage[:float]
436
- assert_equal true, ac_span.baggage[:hash][:another].empty?
437
- assert_equal "blah", ac_span.baggage[:hash][:hash_sublevel]
438
- assert_equal 1, av_span.baggage[:integer]
439
- assert_equal 1.0123948293, av_span.baggage[:float]
440
- assert_equal true, av_span.baggage[:hash][:another].empty?
441
- assert_equal "blah", av_span.baggage[:hash][:hash_sublevel]
328
+ spans = ::Instana.processor.queued_spans
329
+ assert_equal 3, spans.length
330
+
331
+ assert_equal(nil, entry_span.context.baggage)
332
+ assert_equal({:my_bag=>1}, ac_span.context.baggage)
333
+ assert_equal(nil, av_span.context.baggage)
442
334
  end
443
335
  end