instana 1.9.7 → 1.10.0.slimfast

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,67 +1,67 @@
1
- require 'test_helper'
2
-
3
- class TraceTest < Minitest::Test
4
- def test_trace_spans_count
5
- t = ::Instana::Trace.new(:test_trace, { :one => 1, :two => 2 })
6
- t.new_span(:sub_span, { :sub_four => 4 })
7
- t.end_span(:sub_five => 5)
8
- t.end_span(:three => 3)
9
- assert t.spans.size == 2
10
- end
11
-
12
- def test_trace_with_incoming_context
13
- incoming_context = { :trace_id => "1234", :span_id => "4321" }
14
- t = ::Instana::Trace.new(:test_trace, { :one => 1, :two => 2 }, incoming_context)
15
- first_span = t.spans.first
16
- assert_equal "1234", first_span[:t]
17
- assert_equal "4321", first_span[:p]
18
- assert t.spans.size == 1
19
- end
20
-
21
- def test_max_value_of_generated_id
22
- # Max is the maximum value for a Java signed long
23
- max_value = 9223372036854775807
24
- 1000.times do
25
- assert ::Instana::Util.generate_id <= max_value
26
- end
27
- end
28
-
29
- def test_min_value_of_generated_id
30
- # Max is the maximum value for a Java signed long
31
- max_value = -9223372036854775808
32
- 1000.times do
33
- assert ::Instana::Util.generate_id >= max_value
34
- end
35
- end
36
-
37
- def test_entry_span_doesnt_have_stack_by_default
38
- t = ::Instana::Trace.new(:rack)
39
- first_span = t.spans.first
40
- assert !first_span.key?(:stack)
41
- end
42
-
43
- def test_entry_span_has_stack_by_config
44
- ::Instana.config[:collect_backtraces] = true
45
- t = ::Instana::Trace.new(:rack)
46
- first_span = t.spans.first
47
- assert first_span.key?(:stack)
48
- assert_equal 2, first_span[:stack].count
49
- ::Instana.config[:collect_backtraces] = false
50
- end
51
-
52
- def test_exit_span_doesnt_have_stack_by_default
53
- t = ::Instana::Trace.new(:trace_test)
54
- t.new_span(:excon)
55
- second_span = t.spans.to_a[1]
56
- assert !second_span.key?(:stack)
57
- end
58
-
59
- def test_exit_span_has_stack_by_config
60
- ::Instana.config[:collect_backtraces] = true
61
- t = ::Instana::Trace.new(:trace_test)
62
- t.new_span(:excon)
63
- second_span = t.spans.to_a[1]
64
- assert second_span.key?(:stack)
65
- ::Instana.config[:collect_backtraces] = false
66
- end
67
- end
1
+ # require 'test_helper'
2
+ #
3
+ # class TraceTest < Minitest::Test
4
+ # def test_trace_spans_count
5
+ # t = ::Instana::Trace.new(:test_trace, { :one => 1, :two => 2 })
6
+ # t.new_span(:sub_span, { :sub_four => 4 })
7
+ # t.end_span(:sub_five => 5)
8
+ # t.end_span(:three => 3)
9
+ # assert t.spans.size == 2
10
+ # end
11
+ #
12
+ # def test_trace_with_incoming_context
13
+ # incoming_context = { :trace_id => "1234", :span_id => "4321" }
14
+ # t = ::Instana::Trace.new(:test_trace, { :one => 1, :two => 2 }, incoming_context)
15
+ # first_span = t.spans.first
16
+ # assert_equal "1234", first_span[:t]
17
+ # assert_equal "4321", first_span[:p]
18
+ # assert t.spans.size == 1
19
+ # end
20
+ #
21
+ # def test_max_value_of_generated_id
22
+ # # Max is the maximum value for a Java signed long
23
+ # max_value = 9223372036854775807
24
+ # 1000.times do
25
+ # assert ::Instana::Util.generate_id <= max_value
26
+ # end
27
+ # end
28
+ #
29
+ # def test_min_value_of_generated_id
30
+ # # Max is the maximum value for a Java signed long
31
+ # max_value = -9223372036854775808
32
+ # 1000.times do
33
+ # assert ::Instana::Util.generate_id >= max_value
34
+ # end
35
+ # end
36
+ #
37
+ # def test_entry_span_doesnt_have_stack_by_default
38
+ # t = ::Instana::Trace.new(:rack)
39
+ # first_span = t.spans.first
40
+ # assert !first_span.key?(:stack)
41
+ # end
42
+ #
43
+ # def test_entry_span_has_stack_by_config
44
+ # ::Instana.config[:collect_backtraces] = true
45
+ # t = ::Instana::Trace.new(:rack)
46
+ # first_span = t.spans.first
47
+ # assert first_span.key?(:stack)
48
+ # assert_equal 2, first_span[:stack].count
49
+ # ::Instana.config[:collect_backtraces] = false
50
+ # end
51
+ #
52
+ # def test_exit_span_doesnt_have_stack_by_default
53
+ # t = ::Instana::Trace.new(:trace_test)
54
+ # t.new_span(:excon)
55
+ # second_span = t.spans.to_a[1]
56
+ # assert !second_span.key?(:stack)
57
+ # end
58
+ #
59
+ # def test_exit_span_has_stack_by_config
60
+ # ::Instana.config[:collect_backtraces] = true
61
+ # t = ::Instana::Trace.new(:trace_test)
62
+ # t.new_span(:excon)
63
+ # second_span = t.spans.to_a[1]
64
+ # assert second_span.key?(:stack)
65
+ # ::Instana.config[:collect_backtraces] = false
66
+ # end
67
+ # end
@@ -14,39 +14,37 @@ class TracerAsyncTest < Minitest::Test
14
14
  refute_nil span.context
15
15
 
16
16
  # Current span should still be rack
17
- assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
17
+ assert_equal :rack, ::Instana.tracer.current_span.name
18
18
 
19
19
  # End an asynchronous span
20
20
  ::Instana.tracer.log_async_exit(:my_async_op, { :exit_kv => 1 }, span)
21
21
 
22
22
  # Current span should still be rack
23
- assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
23
+ assert_equal :rack, ::Instana.tracer.current_span.name
24
24
 
25
25
  # End tracing
26
26
  ::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
27
27
 
28
- traces = ::Instana.processor.queued_traces
29
- assert_equal 1, traces.length
30
- t = traces.first
31
- assert_equal 2, t.spans.size
32
- spans = t.spans.to_a
33
- first_span = spans[0]
34
- second_span = spans[1]
28
+ spans = ::Instana.processor.queued_spans
29
+ assert_equal 2, spans.length
30
+
31
+ rack_span = find_first_span_by_name(spans, :rack)
32
+ async_span = find_first_span_by_name(spans, :my_async_op)
35
33
 
36
34
  # Both spans have a duration
37
- assert first_span[:d]
38
- assert second_span[:d]
35
+ assert rack_span[:d]
36
+ assert async_span[:d]
39
37
 
40
38
  # first_span is the parent of first_span
41
- assert_equal first_span[:s], second_span[:p]
39
+ assert_equal rack_span[:s], async_span[:p]
42
40
  # same trace id
43
- assert_equal first_span[:t], second_span[:t]
41
+ assert_equal rack_span[:t], async_span[:t]
44
42
 
45
43
  # KV checks
46
- assert_equal 1, first_span[:data][:rack_start_kv]
47
- assert_equal 1, first_span[:data][:rack_end_kv]
48
- assert_equal 1, second_span[:data][:sdk][:custom][:tags][:entry_kv]
49
- assert_equal 1, second_span[:data][:sdk][:custom][:tags][:exit_kv]
44
+ assert_equal 1, rack_span[:data][:rack_start_kv]
45
+ assert_equal 1, rack_span[:data][:rack_end_kv]
46
+ assert_equal 1, async_span[:data][:sdk][:custom][:tags][:entry_kv]
47
+ assert_equal 1, async_span[:data][:sdk][:custom][:tags][:exit_kv]
50
48
  end
51
49
 
52
50
  def test_diff_thread_async_tracing
@@ -60,7 +58,7 @@ class TracerAsyncTest < Minitest::Test
60
58
  refute_nil t_context.span_id
61
59
 
62
60
  Thread.new do
63
- ::Instana.tracer.log_start_or_continue(:async_thread, { :async_start => 1 }, t_context.to_hash)
61
+ ::Instana.tracer.log_start_or_continue(:async_thread, { :async_start => 1 }, t_context)
64
62
  ::Instana.tracer.log_entry(:sleepy_time, { :tired => 1 })
65
63
  # Sleep beyond the end of this root trace
66
64
  sleep 0.5
@@ -69,7 +67,7 @@ class TracerAsyncTest < Minitest::Test
69
67
  end
70
68
 
71
69
  # Current span should still be rack
72
- assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
70
+ assert_equal :rack, ::Instana.tracer.current_span.name
73
71
 
74
72
  # End tracing
75
73
  ::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
@@ -79,104 +77,43 @@ class TracerAsyncTest < Minitest::Test
79
77
  # Sleep for 1 seconds to wait for the async thread to finish
80
78
  sleep 1
81
79
 
82
- traces = ::Instana.processor.queued_traces
83
- assert_equal 2, traces.length
84
- first_trace, second_trace = traces
80
+ spans = ::Instana.processor.queued_spans
81
+ assert_equal 3, spans.length
85
82
 
86
- # Both traces should have the same ID
87
- assert first_trace.id == second_trace.id
83
+ rack_span = find_first_span_by_name(spans, :rack)
84
+ async_span1 = find_first_span_by_name(spans, :async_thread)
85
+ async_span2 = find_first_span_by_name(spans, :sleepy_time)
88
86
 
89
87
  # Validate the first original thread span
90
- assert_equal 1, first_trace.spans.size
91
- spans = first_trace.spans.to_a
92
- first_span = spans[0]
93
- assert_equal :rack, first_span.name
94
- assert first_span.duration
95
- assert_equal 1, first_span[:data][:rack_start_kv]
96
- assert_equal 1, first_span[:data][:rack_end_kv]
97
-
98
- # Validate the second background thread trace
99
- assert_equal 2, second_trace.spans.size
100
- spans = second_trace.spans.to_a
101
- first_span, second_span = spans
88
+ assert_equal :rack, rack_span[:n]
89
+ assert rack_span[:d]
90
+ assert_equal 1, rack_span[:data][:rack_start_kv]
91
+ assert_equal 1, rack_span[:data][:rack_end_kv]
102
92
 
103
93
  # first span in second trace
104
- assert_equal :async_thread, first_span.name
105
- assert first_span.duration
106
- assert_equal 1, first_span[:data][:sdk][:custom][:tags][:async_start]
107
- assert_equal 1, first_span[:data][:sdk][:custom][:tags][:async_end]
94
+ assert_equal :sdk, async_span1[:n]
95
+ assert_equal :async_thread, async_span1[:data][:sdk][:name]
96
+ assert async_span1[:d]
97
+ assert_equal 1, async_span1[:data][:sdk][:custom][:tags][:async_start]
98
+ assert_equal 1, async_span1[:data][:sdk][:custom][:tags][:async_end]
108
99
 
109
100
  # second span in second trace
110
- assert_equal :sleepy_time, second_span.name
111
- assert second_span.duration
112
- assert_equal 1, second_span[:data][:sdk][:custom][:tags][:tired]
113
- assert_equal 1, second_span[:data][:sdk][:custom][:tags][:wake_up]
101
+ assert_equal :sdk, async_span2[:n]
102
+ assert_equal :sleepy_time, async_span2[:data][:sdk][:name]
103
+ assert async_span2[:d]
104
+ assert_equal 1, async_span2[:data][:sdk][:custom][:tags][:tired]
105
+ assert_equal 1, async_span2[:data][:sdk][:custom][:tags][:wake_up]
114
106
 
115
107
  # Validate linkage
116
- # first_span is the parent of first_span
117
- assert_equal first_span[:s], second_span[:p]
118
- # same trace id
119
- assert_equal first_span[:t], second_span[:t]
120
- end
121
-
122
- def test_never_ending_async
123
- clear_all!
124
-
125
- # Start tracing
126
- ::Instana.tracer.log_start_or_continue(:rack, {:rack_start_kv => 1})
127
-
128
- # Start an asynchronous span
129
- span = ::Instana.tracer.log_async_entry(:my_async_op, { :async_entry_kv => 1})
130
-
131
- refute_nil span
132
- refute_nil span.context
133
-
134
- # Current span should still be rack
135
- assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
136
-
137
- # DON'T end the asynchronous span
138
- # This trace should end up in staging_queue
139
- # ::Instana.tracer.log_async_exit(:my_async_op, { :exit_kv => 1 }, span)
140
-
141
- # Current span should still be rack
142
- assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
143
-
144
- # End tracing
145
- ::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
146
-
147
- # Make sure everything is settled
148
- sleep 0.5
149
-
150
- assert_equal 1, ::Instana.processor.staged_count
151
- assert_equal 0, ::Instana.processor.queue_count
108
+ # All spans have the same trace ID
109
+ assert rack_span[:t]==async_span1[:t] && async_span1[:t]==async_span2[:t]
152
110
 
153
- traces = ::Instana.processor.staged_traces
154
- assert_equal 1, traces.count
111
+ assert_equal async_span2[:p], async_span1[:s]
112
+ assert_equal async_span1[:p], rack_span[:s]
155
113
 
156
- trace = traces.first
157
- assert !trace.complete?
158
- assert_equal 2, trace.spans.size
159
- first_span, second_span = trace.spans.to_a
160
-
161
- # First span should have a duration, second span should NOT
162
- assert first_span.duration
163
- assert !second_span.duration
164
-
165
- # First span validation
166
- assert_equal :rack, first_span.name
167
- assert_equal 1, first_span[:data][:rack_start_kv]
168
- assert_equal 1, first_span[:data][:rack_end_kv]
169
-
170
- # second span validation
171
- assert_equal :my_async_op, second_span.name
172
- assert_equal 1, second_span[:data][:sdk][:custom][:tags][:async_entry_kv]
173
- assert !second_span[:data][:sdk][:custom][:tags].key?(:async_exit_kv)
174
- assert_equal nil, second_span.duration
175
-
176
- # first_span is the parent of first_span
177
- assert_equal first_span[:s], second_span[:p]
178
- # same trace id
179
- assert_equal first_span[:t], second_span[:t]
114
+ assert rack_span[:t] == rack_span[:s]
115
+ assert async_span1[:t] != async_span1[:s]
116
+ assert async_span2[:t] != async_span2[:s]
180
117
  end
181
118
 
182
119
  def test_out_of_order_async_tracing
@@ -186,48 +123,52 @@ class TracerAsyncTest < Minitest::Test
186
123
  ::Instana.tracer.log_start_or_continue(:rack, {:rack_start_kv => 1})
187
124
 
188
125
  # Start three asynchronous spans
189
- span1 = ::Instana.tracer.log_async_entry(:my_async_op, { :entry_kv => 1})
190
- span2 = ::Instana.tracer.log_async_entry(:my_async_op, { :entry_kv => 2})
191
- span3 = ::Instana.tracer.log_async_entry(:my_async_op, { :entry_kv => 3})
126
+ span1 = ::Instana.tracer.log_async_entry(:my_async_op1, { :entry_kv => 1})
127
+ span2 = ::Instana.tracer.log_async_entry(:my_async_op2, { :entry_kv => 2})
128
+ span3 = ::Instana.tracer.log_async_entry(:my_async_op3, { :entry_kv => 3})
192
129
 
193
130
  # Current span should still be rack
194
- assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
131
+ assert_equal :rack, ::Instana.tracer.current_span.name
195
132
 
196
133
  # Log info to the async spans (out of order)
197
- ::Instana.tracer.log_async_info({ :info_kv => 2 }, span2)
198
- ::Instana.tracer.log_async_info({ :info_kv => 1 }, span1)
199
- ::Instana.tracer.log_async_info({ :info_kv => 3 }, span3)
134
+ span2.set_tags({ :info_kv => 2 })
135
+ span1.set_tags({ :info_kv => 1 })
136
+ span3.set_tags({ :info_kv => 3 })
200
137
 
201
138
  # Log out of order errors to the async spans
202
- ::Instana.tracer.log_async_error(Exception.new("Async span 3"), span3)
203
- ::Instana.tracer.log_async_error(Exception.new("Async span 2"), span2)
139
+ span3.add_error(Exception.new("Async span 3"))
140
+ span2.add_error(Exception.new("Async span 3"))
204
141
 
205
142
  # End two out of order asynchronous spans
206
- ::Instana.tracer.log_async_exit(:my_async_op, { :exit_kv => 3 }, span3)
207
- ::Instana.tracer.log_async_exit(:my_async_op, { :exit_kv => 2 }, span2)
143
+ span3.set_tags({ :exit_kv => 3 })
144
+ span3.close
145
+ span2.set_tags({ :exit_kv => 2 })
146
+ span2.close
208
147
 
209
148
  # Current span should still be rack
210
- assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
149
+ assert_equal :rack, ::Instana.tracer.current_span.name
211
150
 
212
151
  # End tracing
213
152
  ::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
214
153
 
215
154
  # Log an error to and close out the remaining async span after the parent trace has finished
216
- ::Instana.tracer.log_async_error(Exception.new("Async span 1"), span1)
217
- ::Instana.tracer.log_async_exit(:my_async_op, { :exit_kv => 1 }, span1)
218
-
219
- # Run process_staged to move staged complete traces to main queue
220
- ::Instana.processor.process_staged
155
+ span1.add_error(Exception.new("Async span 1"))
156
+ span1.set_tags({ :exit_kv => 1 })
157
+ span1.close
221
158
 
222
- # Begin trace validation
223
- traces = ::Instana.processor.queued_traces
159
+ spans = ::Instana.processor.queued_spans
160
+ assert_equal 4, spans.length
224
161
 
225
- assert_equal 1, traces.length
226
- trace = traces.first
227
- assert_equal 4, trace.spans.size
228
- first_span, second_span, third_span, fourth_span = trace.spans.to_a
162
+ first_span = find_first_span_by_name(spans, :rack)
163
+ second_span = find_first_span_by_name(spans, :my_async_op1)
164
+ third_span = find_first_span_by_name(spans, :my_async_op2)
165
+ fourth_span = find_first_span_by_name(spans, :my_async_op3)
229
166
 
230
- assert trace.complete?
167
+ # Assure all spans have completed
168
+ assert first_span.key?(:d)
169
+ assert second_span.key?(:d)
170
+ assert third_span.key?(:d)
171
+ assert fourth_span.key?(:d)
231
172
 
232
173
  # Linkage
233
174
  assert_equal first_span[:s], second_span[:p]
@@ -239,15 +180,10 @@ class TracerAsyncTest < Minitest::Test
239
180
  assert_equal first_span[:t], third_span[:t]
240
181
  assert_equal first_span[:t], fourth_span[:t]
241
182
 
242
- assert !first_span.custom?
243
- assert second_span.custom?
244
- assert third_span.custom?
245
- assert fourth_span.custom?
246
-
247
- assert !first_span[:deferred]
248
- assert second_span[:deferred]
249
- assert third_span[:deferred]
250
- assert fourth_span[:deferred]
183
+ assert first_span[:n] != :sdk
184
+ assert second_span[:n] == :sdk
185
+ assert third_span[:n] == :sdk
186
+ assert fourth_span[:n] == :sdk
251
187
 
252
188
  # KV checks
253
189
  assert_equal 1, first_span[:data][:rack_start_kv]
@@ -259,40 +195,4 @@ class TracerAsyncTest < Minitest::Test
259
195
  assert_equal 3, fourth_span[:data][:sdk][:custom][:tags][:entry_kv]
260
196
  assert_equal 3, fourth_span[:data][:sdk][:custom][:tags][:exit_kv]
261
197
  end
262
-
263
-
264
- def test_staged_trace_moved_to_queue
265
- clear_all!
266
-
267
- # Start tracing
268
- ::Instana.tracer.log_start_or_continue(:rack, {:rack_start_kv => 1})
269
-
270
- # Start an asynchronous span
271
- span = ::Instana.tracer.log_async_entry(:my_async_op, { :async_entry_kv => 1})
272
-
273
- refute_nil span
274
- refute_nil span.context
275
-
276
- # Current span should still be rack
277
- assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
278
-
279
- # End tracing with a still outstanding async span (above)
280
- ::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
281
-
282
- # Make sure everything is settled
283
- sleep 0.5
284
-
285
- # We should have one staged trace and no queue traces
286
- assert_equal 1, ::Instana.processor.staged_count
287
- assert_equal 0, ::Instana.processor.queue_count
288
-
289
- # Now end the async span completing the trace
290
- ::Instana.tracer.log_async_exit(:my_async_op, { :exit_kv => 1 }, span)
291
-
292
- ::Instana.processor.process_staged
293
-
294
- # We should have one staged trace and no queue traces
295
- assert_equal 0, ::Instana.processor.staged_count
296
- assert_equal 1, ::Instana.processor.queue_count
297
- end
298
198
  end