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.
- checksums.yaml +4 -4
- data/lib/instana/agent.rb +19 -19
- data/lib/instana/agent/helpers.rb +2 -2
- data/lib/instana/agent/tasks.rb +2 -2
- data/lib/instana/collectors/gc.rb +1 -1
- data/lib/instana/collectors/memory.rb +1 -1
- data/lib/instana/collectors/thread.rb +1 -1
- data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +1 -1
- data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +1 -1
- data/lib/instana/helpers.rb +2 -2
- data/lib/instana/instrumentation.rb +1 -1
- data/lib/instana/instrumentation/excon.rb +8 -5
- data/lib/instana/instrumentation/rack.rb +2 -2
- data/lib/instana/instrumentation/resque.rb +3 -3
- data/lib/instana/tracer.rb +92 -117
- data/lib/instana/tracing/processor.rb +18 -133
- data/lib/instana/tracing/span.rb +40 -35
- data/lib/instana/tracing/span_context.rb +3 -1
- data/lib/instana/util.rb +5 -5
- data/lib/instana/version.rb +1 -1
- data/lib/opentracing.rb +1 -1
- data/test/frameworks/rack_test.rb +6 -11
- data/test/frameworks/rails/actioncontroller_test.rb +32 -62
- data/test/frameworks/rails/actionview5_test.rb +91 -132
- data/test/frameworks/rails/activerecord5_test.rb +14 -17
- data/test/instrumentation/dalli_test.rb +51 -72
- data/test/instrumentation/excon_test.rb +70 -94
- data/test/instrumentation/grpc_test.rb +164 -126
- data/test/instrumentation/net-http_test.rb +48 -57
- data/test/instrumentation/redis_test.rb +4 -6
- data/test/instrumentation/resque_test.rb +41 -41
- data/test/instrumentation/rest-client_test.rb +25 -31
- data/test/instrumentation/sidekiq-client_test.rb +12 -20
- data/test/instrumentation/sidekiq-worker_test.rb +48 -63
- data/test/jobs/resque_error_job.rb +7 -1
- data/test/jobs/resque_fast_job.rb +7 -1
- data/test/servers/sidekiq/worker.rb +1 -3
- data/test/test_helper.rb +58 -0
- data/test/tracing/custom_test.rb +11 -19
- data/test/tracing/opentracing_test.rb +48 -156
- data/test/tracing/trace_test.rb +67 -67
- data/test/tracing/tracer_async_test.rb +75 -175
- data/test/tracing/tracer_test.rb +75 -75
- metadata +4 -5
- data/lib/instana/tracing/trace.rb +0 -316
data/test/tracing/trace_test.rb
CHANGED
@@ -1,67 +1,67 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TraceTest < Minitest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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.
|
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.
|
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
|
-
|
29
|
-
assert_equal
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
38
|
-
assert
|
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
|
39
|
+
assert_equal rack_span[:s], async_span[:p]
|
42
40
|
# same trace id
|
43
|
-
assert_equal
|
41
|
+
assert_equal rack_span[:t], async_span[:t]
|
44
42
|
|
45
43
|
# KV checks
|
46
|
-
assert_equal 1,
|
47
|
-
assert_equal 1,
|
48
|
-
assert_equal 1,
|
49
|
-
assert_equal 1,
|
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
|
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.
|
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
|
-
|
83
|
-
assert_equal
|
84
|
-
first_trace, second_trace = traces
|
80
|
+
spans = ::Instana.processor.queued_spans
|
81
|
+
assert_equal 3, spans.length
|
85
82
|
|
86
|
-
|
87
|
-
|
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
|
91
|
-
|
92
|
-
|
93
|
-
assert_equal
|
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 :
|
105
|
-
|
106
|
-
|
107
|
-
assert_equal 1,
|
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 :
|
111
|
-
|
112
|
-
|
113
|
-
assert_equal 1,
|
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
|
-
#
|
117
|
-
|
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
|
-
|
154
|
-
assert_equal
|
111
|
+
assert_equal async_span2[:p], async_span1[:s]
|
112
|
+
assert_equal async_span1[:p], rack_span[:s]
|
155
113
|
|
156
|
-
|
157
|
-
assert
|
158
|
-
|
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(:
|
190
|
-
span2 = ::Instana.tracer.log_async_entry(:
|
191
|
-
span3 = ::Instana.tracer.log_async_entry(:
|
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.
|
131
|
+
assert_equal :rack, ::Instana.tracer.current_span.name
|
195
132
|
|
196
133
|
# Log info to the async spans (out of order)
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
203
|
-
|
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
|
-
|
207
|
-
|
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.
|
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
|
-
|
217
|
-
|
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
|
-
|
223
|
-
|
159
|
+
spans = ::Instana.processor.queued_spans
|
160
|
+
assert_equal 4, spans.length
|
224
161
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
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
|
-
|
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
|
243
|
-
assert second_span
|
244
|
-
assert third_span
|
245
|
-
assert fourth_span
|
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
|