instana 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -0
- data/.gitignore +1 -0
- data/.travis.yml +24 -2
- data/Gemfile +2 -22
- data/README.md +1 -1
- data/Rakefile +15 -0
- data/Tracing.md +29 -2
- data/gemfiles/libraries.gemfile +50 -0
- data/gemfiles/rails32.gemfile +45 -0
- data/gemfiles/rails42.gemfile +44 -0
- data/gemfiles/rails50.gemfile +44 -0
- data/instana.gemspec +6 -8
- data/lib/instana/config.rb +7 -5
- data/lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb +55 -0
- data/lib/instana/frameworks/instrumentation/action_controller.rb +105 -0
- data/lib/instana/frameworks/instrumentation/active_record.rb +22 -0
- data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +81 -0
- data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +56 -0
- data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +71 -0
- data/lib/instana/frameworks/rails.rb +5 -0
- data/lib/instana/test.rb +40 -0
- data/lib/instana/tracer.rb +19 -0
- data/lib/instana/tracing/span.rb +3 -3
- data/lib/instana/version.rb +1 -1
- data/log/.keep +0 -0
- data/test/agent/agent_test.rb +139 -0
- data/test/apps/cuba.rb +15 -0
- data/test/apps/roda.rb +10 -0
- data/test/apps/sinatra.rb +5 -0
- data/test/config_test.rb +17 -0
- data/test/frameworks/cuba_test.rb +44 -0
- data/test/frameworks/rack_test.rb +152 -0
- data/test/frameworks/rails/actioncontroller_test.rb +123 -0
- data/test/frameworks/rails/activerecord3_test.rb +134 -0
- data/test/frameworks/rails/activerecord4_test.rb +134 -0
- data/test/frameworks/rails/activerecord5_test.rb +90 -0
- data/test/frameworks/roda_test.rb +44 -0
- data/test/frameworks/sinatra_test.rb +44 -0
- data/test/instana_test.rb +27 -0
- data/test/instrumentation/dalli_test.rb +274 -0
- data/test/instrumentation/excon_test.rb +171 -0
- data/test/instrumentation/net-http_test.rb +140 -0
- data/test/instrumentation/rest-client_test.rb +61 -0
- data/test/models/block.rb +18 -0
- data/test/servers/rackapp_6511.rb +20 -0
- data/test/servers/rails_3205.rb +95 -0
- data/test/test_helper.rb +39 -0
- data/test/tracing/custom_test.rb +143 -0
- data/test/tracing/id_management_test.rb +96 -0
- data/test/tracing/opentracing_test.rb +377 -0
- data/test/tracing/trace_test.rb +50 -0
- data/test/tracing/tracer_async_test.rb +298 -0
- data/test/tracing/tracer_test.rb +202 -0
- metadata +114 -4
@@ -0,0 +1,50 @@
|
|
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_has_stack_with_limit
|
38
|
+
t = ::Instana::Trace.new(:rack)
|
39
|
+
first_span = t.spans.first
|
40
|
+
assert first_span.key?(:stack)
|
41
|
+
assert_equal 2, first_span[:stack].count
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_exit_span_has_stack
|
45
|
+
t = ::Instana::Trace.new(:trace_test)
|
46
|
+
t.new_span(:excon)
|
47
|
+
second_span = t.spans.to_a[1]
|
48
|
+
assert second_span.key?(:stack)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,298 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TracerAsyncTest < Minitest::Test
|
4
|
+
def test_same_thread_async_tracing
|
5
|
+
clear_all!
|
6
|
+
|
7
|
+
# Start tracing
|
8
|
+
::Instana.tracer.log_start_or_continue(:rack, {:rack_start_kv => 1})
|
9
|
+
|
10
|
+
# Start an asynchronous span
|
11
|
+
span = ::Instana.tracer.log_async_entry(:my_async_op, { :entry_kv => 1})
|
12
|
+
|
13
|
+
refute_nil span
|
14
|
+
refute_nil span.context
|
15
|
+
|
16
|
+
# Current span should still be rack
|
17
|
+
assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
|
18
|
+
|
19
|
+
# End an asynchronous span
|
20
|
+
::Instana.tracer.log_async_exit(:my_async_op, { :exit_kv => 1 }, span)
|
21
|
+
|
22
|
+
# Current span should still be rack
|
23
|
+
assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
|
24
|
+
|
25
|
+
# End tracing
|
26
|
+
::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
|
27
|
+
|
28
|
+
traces = ::Instana.processor.queued_traces
|
29
|
+
assert_equal 1, traces.count
|
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]
|
35
|
+
|
36
|
+
# Both spans have a duration
|
37
|
+
assert first_span[:d]
|
38
|
+
assert second_span[:d]
|
39
|
+
|
40
|
+
# first_span is the parent of first_span
|
41
|
+
assert_equal first_span[:s], second_span[:p]
|
42
|
+
# same trace id
|
43
|
+
assert_equal first_span[:t], second_span[:t]
|
44
|
+
|
45
|
+
# 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][:entry_kv]
|
49
|
+
assert_equal 1, second_span[:data][:sdk][:custom][:exit_kv]
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_diff_thread_async_tracing
|
53
|
+
clear_all!
|
54
|
+
|
55
|
+
# Start tracing
|
56
|
+
::Instana.tracer.log_start_or_continue(:rack, {:rack_start_kv => 1})
|
57
|
+
|
58
|
+
t_context = ::Instana.tracer.context
|
59
|
+
refute_nil t_context.trace_id
|
60
|
+
refute_nil t_context.span_id
|
61
|
+
|
62
|
+
Thread.new do
|
63
|
+
::Instana.tracer.log_start_or_continue(:async_thread, { :async_start => 1 }, t_context.to_hash)
|
64
|
+
::Instana.tracer.log_entry(:sleepy_time, { :tired => 1 })
|
65
|
+
# Sleep beyond the end of this root trace
|
66
|
+
sleep 0.5
|
67
|
+
::Instana.tracer.log_exit(:sleepy_time, { :wake_up => 1})
|
68
|
+
::Instana.tracer.log_end(:async_thread, { :async_end => 1 })
|
69
|
+
end
|
70
|
+
|
71
|
+
# Current span should still be rack
|
72
|
+
assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
|
73
|
+
|
74
|
+
# End tracing
|
75
|
+
::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
|
76
|
+
|
77
|
+
assert_equal false, ::Instana.tracer.tracing?
|
78
|
+
|
79
|
+
# Sleep for 1 seconds to wait for the async thread to finish
|
80
|
+
sleep 1
|
81
|
+
|
82
|
+
traces = ::Instana.processor.queued_traces
|
83
|
+
assert_equal 2, traces.count
|
84
|
+
first_trace, second_trace = traces
|
85
|
+
|
86
|
+
# Both traces should have the same ID
|
87
|
+
assert first_trace.id == second_trace.id
|
88
|
+
|
89
|
+
# 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
|
102
|
+
|
103
|
+
# 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][:async_start]
|
107
|
+
assert_equal 1, first_span[:data][:sdk][:custom][:async_end]
|
108
|
+
|
109
|
+
# 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][:tired]
|
113
|
+
assert_equal 1, second_span[:data][:sdk][:custom][:wake_up]
|
114
|
+
|
115
|
+
# 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
|
152
|
+
|
153
|
+
traces = ::Instana.processor.staged_traces
|
154
|
+
assert_equal 1, traces.count
|
155
|
+
|
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][:async_entry_kv]
|
173
|
+
assert !second_span[:data][:sdk][:custom].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]
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_out_of_order_async_tracing
|
183
|
+
clear_all!
|
184
|
+
|
185
|
+
# Start tracing
|
186
|
+
::Instana.tracer.log_start_or_continue(:rack, {:rack_start_kv => 1})
|
187
|
+
|
188
|
+
# 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})
|
192
|
+
|
193
|
+
# Current span should still be rack
|
194
|
+
assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
|
195
|
+
|
196
|
+
# 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)
|
200
|
+
|
201
|
+
# 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)
|
204
|
+
|
205
|
+
# 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)
|
208
|
+
|
209
|
+
# Current span should still be rack
|
210
|
+
assert_equal :rack, ::Instana.tracer.current_trace.current_span_name
|
211
|
+
|
212
|
+
# End tracing
|
213
|
+
::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
|
214
|
+
|
215
|
+
# 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
|
221
|
+
|
222
|
+
# Begin trace validation
|
223
|
+
traces = ::Instana.processor.queued_traces
|
224
|
+
|
225
|
+
assert_equal 1, traces.count
|
226
|
+
trace = traces.first
|
227
|
+
assert_equal 4, trace.spans.size
|
228
|
+
first_span, second_span, third_span, fourth_span = trace.spans.to_a
|
229
|
+
|
230
|
+
assert trace.complete?
|
231
|
+
|
232
|
+
# Linkage
|
233
|
+
assert_equal first_span[:s], second_span[:p]
|
234
|
+
assert_equal first_span[:s], third_span[:p]
|
235
|
+
assert_equal first_span[:s], fourth_span[:p]
|
236
|
+
|
237
|
+
# same trace id
|
238
|
+
assert_equal first_span[:t], second_span[:t]
|
239
|
+
assert_equal first_span[:t], third_span[:t]
|
240
|
+
assert_equal first_span[:t], fourth_span[:t]
|
241
|
+
|
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[:async]
|
248
|
+
assert second_span[:async]
|
249
|
+
assert third_span[:async]
|
250
|
+
assert fourth_span[:async]
|
251
|
+
|
252
|
+
# KV checks
|
253
|
+
assert_equal 1, first_span[:data][:rack_start_kv]
|
254
|
+
assert_equal 1, first_span[:data][:rack_end_kv]
|
255
|
+
assert_equal 1, second_span[:data][:sdk][:custom][:entry_kv]
|
256
|
+
assert_equal 1, second_span[:data][:sdk][:custom][:exit_kv]
|
257
|
+
assert_equal 2, third_span[:data][:sdk][:custom][:entry_kv]
|
258
|
+
assert_equal 2, third_span[:data][:sdk][:custom][:exit_kv]
|
259
|
+
assert_equal 3, fourth_span[:data][:sdk][:custom][:entry_kv]
|
260
|
+
assert_equal 3, fourth_span[:data][:sdk][:custom][:exit_kv]
|
261
|
+
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
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TracerTest < Minitest::Test
|
4
|
+
def test_that_it_has_a_valid_tracer
|
5
|
+
refute_nil ::Instana.tracer
|
6
|
+
assert ::Instana.tracer.is_a?(::Instana::Tracer)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_basic_trace_block
|
10
|
+
clear_all!
|
11
|
+
|
12
|
+
assert_equal false, ::Instana.tracer.tracing?
|
13
|
+
|
14
|
+
::Instana.tracer.start_or_continue_trace(:rack, {:one => 1}) do
|
15
|
+
assert_equal true, ::Instana.tracer.tracing?
|
16
|
+
sleep 0.5
|
17
|
+
end
|
18
|
+
|
19
|
+
traces = ::Instana.processor.queued_traces
|
20
|
+
assert_equal 1, traces.count
|
21
|
+
t = traces.first
|
22
|
+
assert_equal 1, t.spans.size
|
23
|
+
assert t.valid?
|
24
|
+
|
25
|
+
first_span = t.spans.first
|
26
|
+
assert_equal :rack, first_span[:n]
|
27
|
+
assert_equal :ruby, first_span[:ta]
|
28
|
+
assert first_span.key?(:data)
|
29
|
+
assert_equal 1, first_span[:data][:one]
|
30
|
+
assert first_span.key?(:f)
|
31
|
+
assert first_span[:f].key?(:e)
|
32
|
+
assert first_span[:f].key?(:h)
|
33
|
+
assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_errors_are_properly_propogated
|
37
|
+
clear_all!
|
38
|
+
exception_raised = false
|
39
|
+
begin
|
40
|
+
::Instana.tracer.start_or_continue_trace(:rack, {:one => 1}) do
|
41
|
+
raise Exception.new('Error in block - this should continue to propogate outside of tracing')
|
42
|
+
end
|
43
|
+
rescue Exception
|
44
|
+
exception_raised = true
|
45
|
+
end
|
46
|
+
|
47
|
+
assert exception_raised
|
48
|
+
|
49
|
+
traces = ::Instana.processor.queued_traces
|
50
|
+
assert_equal 1, traces.count
|
51
|
+
t = traces.first
|
52
|
+
assert_equal 1, t.spans.size
|
53
|
+
assert t.valid?
|
54
|
+
|
55
|
+
first_span = t.spans.first
|
56
|
+
assert_equal :rack, first_span[:n]
|
57
|
+
assert_equal :ruby, first_span[:ta]
|
58
|
+
assert first_span.key?(:data)
|
59
|
+
assert_equal 1, first_span[:data][:one]
|
60
|
+
assert first_span.key?(:f)
|
61
|
+
assert first_span[:f].key?(:e)
|
62
|
+
assert first_span[:f].key?(:h)
|
63
|
+
assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
|
64
|
+
assert t.has_error?
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_complex_trace_block
|
68
|
+
clear_all!
|
69
|
+
::Instana.tracer.start_or_continue_trace(:rack, {:one => 1}) do
|
70
|
+
sleep 0.2
|
71
|
+
::Instana.tracer.trace(:sub_block, {:sub_two => 2}) do
|
72
|
+
sleep 0.2
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
traces = ::Instana.processor.queued_traces
|
77
|
+
assert_equal 1, traces.count
|
78
|
+
t = traces.first
|
79
|
+
assert_equal 2, t.spans.size
|
80
|
+
assert t.valid?
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_basic_low_level_tracing
|
84
|
+
clear_all!
|
85
|
+
|
86
|
+
assert_equal false, ::Instana.tracer.tracing?
|
87
|
+
# Start tracing
|
88
|
+
::Instana.tracer.log_start_or_continue(:rack, {:one => 1})
|
89
|
+
assert_equal true, ::Instana.tracer.tracing?
|
90
|
+
::Instana.tracer.log_info({:info_logged => 1})
|
91
|
+
# End tracing
|
92
|
+
::Instana.tracer.log_end(:rack, {:close_one => 1})
|
93
|
+
assert_equal false, ::Instana.tracer.tracing?
|
94
|
+
|
95
|
+
traces = ::Instana.processor.queued_traces
|
96
|
+
assert_equal 1, traces.count
|
97
|
+
t = traces.first
|
98
|
+
assert_equal 1, t.spans.size
|
99
|
+
assert t.valid?
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_complex_low_level_tracing
|
103
|
+
clear_all!
|
104
|
+
|
105
|
+
assert_equal false, ::Instana.tracer.tracing?
|
106
|
+
|
107
|
+
# Start tracing
|
108
|
+
::Instana.tracer.log_start_or_continue(:rack, {:one => 1})
|
109
|
+
assert_equal true, ::Instana.tracer.tracing?
|
110
|
+
::Instana.tracer.log_info({:info_logged => 1})
|
111
|
+
|
112
|
+
# Start tracing a sub span
|
113
|
+
::Instana.tracer.log_entry(:sub_task)
|
114
|
+
assert_equal true, ::Instana.tracer.tracing?
|
115
|
+
::Instana.tracer.log_info({:sub_task_info => 1})
|
116
|
+
# Exit from the sub span
|
117
|
+
::Instana.tracer.log_exit(:sub_task, {:sub_task_exit_info => 1})
|
118
|
+
assert_equal true, ::Instana.tracer.tracing?
|
119
|
+
|
120
|
+
# End tracing
|
121
|
+
::Instana.tracer.log_end(:rack, {:close_one => 1})
|
122
|
+
assert_equal false, ::Instana.tracer.tracing?
|
123
|
+
|
124
|
+
traces = ::Instana.processor.queued_traces
|
125
|
+
assert_equal 1, traces.count
|
126
|
+
|
127
|
+
t = traces.first
|
128
|
+
assert_equal 2, t.spans.size
|
129
|
+
assert t.valid?
|
130
|
+
|
131
|
+
first_span = t.spans.first
|
132
|
+
assert_equal :rack, first_span[:n]
|
133
|
+
assert_equal :ruby, first_span[:ta]
|
134
|
+
assert first_span.key?(:data)
|
135
|
+
assert_equal 1, first_span[:data][:one]
|
136
|
+
assert first_span.key?(:f)
|
137
|
+
assert first_span[:f].key?(:e)
|
138
|
+
assert first_span[:f].key?(:h)
|
139
|
+
assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_block_tracing_error_capture
|
143
|
+
clear_all!
|
144
|
+
exception_raised = false
|
145
|
+
begin
|
146
|
+
::Instana.tracer.start_or_continue_trace(:test_trace, {:one => 1}) do
|
147
|
+
raise Exception.new("Block exception test error")
|
148
|
+
end
|
149
|
+
rescue Exception
|
150
|
+
exception_raised = true
|
151
|
+
end
|
152
|
+
|
153
|
+
assert exception_raised
|
154
|
+
|
155
|
+
traces = ::Instana.processor.queued_traces
|
156
|
+
assert_equal 1, traces.count
|
157
|
+
|
158
|
+
t = traces.first
|
159
|
+
assert_equal 1, t.spans.size
|
160
|
+
assert t.valid?
|
161
|
+
assert t.has_error?
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_low_level_error_logging
|
165
|
+
clear_all!
|
166
|
+
::Instana.tracer.log_start_or_continue(:test_trace, {:one => 1})
|
167
|
+
::Instana.tracer.log_info({:info_logged => 1})
|
168
|
+
::Instana.tracer.log_error(Exception.new("Low level tracing api error"))
|
169
|
+
::Instana.tracer.log_end(:test_trace, {:close_one => 1})
|
170
|
+
|
171
|
+
traces = ::Instana.processor.queued_traces
|
172
|
+
assert_equal 1, traces.count
|
173
|
+
|
174
|
+
t = traces.first
|
175
|
+
assert_equal 1, t.spans.size
|
176
|
+
assert t.valid?
|
177
|
+
assert t.has_error?
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_instana_headers_in_response
|
181
|
+
clear_all!
|
182
|
+
::Instana.tracer.start_or_continue_trace(:rack, {:one => 1}) do
|
183
|
+
sleep 0.5
|
184
|
+
end
|
185
|
+
|
186
|
+
traces = ::Instana.processor.queued_traces
|
187
|
+
assert_equal 1, traces.count
|
188
|
+
t = traces.first
|
189
|
+
assert_equal 1, t.spans.size
|
190
|
+
assert t.valid?
|
191
|
+
|
192
|
+
first_span = t.spans.first
|
193
|
+
assert_equal :rack, first_span[:n]
|
194
|
+
assert_equal :ruby, first_span[:ta]
|
195
|
+
assert first_span.key?(:data)
|
196
|
+
assert_equal 1, first_span[:data][:one]
|
197
|
+
assert first_span.key?(:f)
|
198
|
+
assert first_span[:f].key?(:e)
|
199
|
+
assert first_span[:f].key?(:h)
|
200
|
+
assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
|
201
|
+
end
|
202
|
+
end
|