instana 1.217.0 → 2.0.0
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/.circleci/config.yml +101 -225
- data/.tekton/.currency/scripts/generate_report.py +194 -22
- data/.tekton/pipeline.yaml +65 -152
- data/.tekton/prepuller-restart-service-account.yaml +31 -0
- data/.tekton/ruby-tracer-prepuller-cronjob.yaml +20 -0
- data/.tekton/ruby-tracer-prepuller.yaml +27 -26
- data/.tekton/task.yaml +31 -27
- data/Gemfile +5 -0
- data/README.md +2 -1
- data/Rakefile +1 -1
- data/examples/otel.rb +98 -0
- data/examples/tracing.rb +1 -0
- data/gemfiles/rails_61.gemfile +1 -0
- data/gemfiles/rails_70.gemfile +1 -0
- data/instana.gemspec +5 -0
- data/lib/instana/base.rb +4 -2
- data/lib/instana/instrumentation/action_cable.rb +8 -4
- data/lib/instana/instrumentation/action_controller.rb +2 -4
- data/lib/instana/instrumentation/action_mailer.rb +1 -1
- data/lib/instana/instrumentation/action_view.rb +4 -4
- data/lib/instana/instrumentation/active_job.rb +26 -13
- data/lib/instana/instrumentation/active_record.rb +1 -1
- data/lib/instana/instrumentation/aws_sdk_dynamodb.rb +1 -1
- data/lib/instana/instrumentation/aws_sdk_lambda.rb +1 -1
- data/lib/instana/instrumentation/aws_sdk_s3.rb +1 -1
- data/lib/instana/instrumentation/aws_sdk_sns.rb +1 -1
- data/lib/instana/instrumentation/aws_sdk_sqs.rb +1 -1
- data/lib/instana/instrumentation/dalli.rb +1 -1
- data/lib/instana/instrumentation/excon.rb +2 -2
- data/lib/instana/instrumentation/graphql.rb +3 -3
- data/lib/instana/instrumentation/grpc.rb +14 -13
- data/lib/instana/instrumentation/mongo.rb +3 -3
- data/lib/instana/instrumentation/net-http.rb +5 -4
- data/lib/instana/instrumentation/rack.rb +36 -4
- data/lib/instana/instrumentation/redis.rb +1 -1
- data/lib/instana/instrumentation/resque.rb +10 -8
- data/lib/instana/instrumentation/rest-client.rb +4 -4
- data/lib/instana/instrumentation/sequel.rb +3 -3
- data/lib/instana/instrumentation/shoryuken.rb +4 -1
- data/lib/instana/instrumentation/sidekiq-client.rb +21 -19
- data/lib/instana/instrumentation/sidekiq-worker.rb +22 -21
- data/lib/instana/instrumented_logger.rb +1 -1
- data/lib/instana/samplers/result.rb +32 -0
- data/lib/instana/samplers/samplers.rb +76 -0
- data/lib/instana/serverless.rb +4 -2
- data/lib/instana/setup.rb +4 -5
- data/lib/instana/trace/export.rb +36 -0
- data/lib/instana/{tracing → trace}/processor.rb +19 -15
- data/lib/instana/trace/span.rb +532 -0
- data/lib/instana/{tracing → trace}/span_context.rb +17 -8
- data/lib/instana/trace/span_kind.rb +51 -0
- data/lib/instana/trace/span_limits.rb +63 -0
- data/lib/instana/{tracer.rb → trace/tracer.rb} +106 -54
- data/lib/instana/trace/tracer_provider.rb +198 -0
- data/lib/instana/trace.rb +74 -0
- data/lib/instana/util.rb +11 -0
- data/lib/instana/version.rb +1 -1
- data/test/frameworks/sinatra_test.rb +2 -1
- data/test/instrumentation/aws_test.rb +7 -7
- data/test/instrumentation/dalli_test.rb +8 -8
- data/test/instrumentation/excon_test.rb +3 -3
- data/test/instrumentation/graphql_test.rb +4 -4
- data/test/instrumentation/grpc_test.rb +8 -8
- data/test/instrumentation/mongo_test.rb +1 -1
- data/test/instrumentation/net_http_test.rb +6 -6
- data/test/instrumentation/rails_action_cable_test.rb +2 -2
- data/test/instrumentation/rails_action_mailer_test.rb +1 -1
- data/test/instrumentation/rails_active_job_test.rb +1 -1
- data/test/instrumentation/rails_active_record_database_missing_test.rb +2 -3
- data/test/instrumentation/rails_active_record_test.rb +8 -7
- data/test/instrumentation/redis_test.rb +7 -7
- data/test/instrumentation/resque_test.rb +5 -5
- data/test/instrumentation/rest_client_test.rb +1 -2
- data/test/instrumentation/sequel_test.rb +12 -6
- data/test/instrumentation/sidekiq-client_test.rb +2 -2
- data/test/instrumentation/sidekiq-worker_test.rb +2 -2
- data/test/{tracing → trace}/custom_test.rb +32 -25
- data/test/{tracing → trace}/id_management_test.rb +0 -2
- data/test/{tracing → trace}/instrumented_logger_test.rb +1 -1
- data/test/{tracing → trace}/processor_test.rb +6 -6
- data/test/{tracing → trace}/span_context_test.rb +3 -3
- data/test/{tracing → trace}/span_test.rb +7 -7
- data/test/{tracing → trace}/tracer_async_test.rb +43 -30
- data/test/trace/tracer_provider_test.rb +148 -0
- data/test/{tracing → trace}/tracer_test.rb +48 -37
- metadata +105 -32
- data/examples/opentracing.rb +0 -35
- data/lib/instana/open_tracing/carrier.rb +0 -7
- data/lib/instana/open_tracing/instana_tracer.rb +0 -99
- data/lib/instana/tracing/span.rb +0 -431
- data/lib/opentracing.rb +0 -32
- data/test/tracing/opentracing_test.rb +0 -382
@@ -9,11 +9,12 @@ class CustomTracingTest < Minitest::Test
|
|
9
9
|
|
10
10
|
assert_equal false, ::Instana.tracer.tracing?
|
11
11
|
# Start tracing
|
12
|
-
::Instana.tracer.
|
12
|
+
span = ::Instana.tracer.start_span(:custom_trace, attributes: {:one => 1})
|
13
13
|
assert_equal true, ::Instana.tracer.tracing?
|
14
|
-
|
14
|
+
span.add_attributes({:info_logged => 1})
|
15
15
|
# End tracing
|
16
|
-
|
16
|
+
span.add_attributes({:close_one => 1})
|
17
|
+
span.finish
|
17
18
|
assert_equal false, ::Instana.tracer.tracing?
|
18
19
|
|
19
20
|
spans = ::Instana.processor.queued_spans
|
@@ -23,7 +24,7 @@ class CustomTracingTest < Minitest::Test
|
|
23
24
|
assert_equal :sdk, first_span[:n]
|
24
25
|
|
25
26
|
assert first_span[:ts].is_a?(Integer)
|
26
|
-
assert first_span[:ts]
|
27
|
+
assert first_span[:ts].positive?
|
27
28
|
assert first_span[:d].is_a?(Integer)
|
28
29
|
assert first_span[:d].between?(0, 5)
|
29
30
|
|
@@ -50,21 +51,21 @@ class CustomTracingTest < Minitest::Test
|
|
50
51
|
|
51
52
|
kvs = {}
|
52
53
|
kvs[:on_entry_kv] = 1
|
53
|
-
kvs[:arguments] = [[1,2,3], "test_arg", :ok]
|
54
|
+
kvs[:arguments] = [[1, 2, 3], "test_arg", :ok]
|
54
55
|
kvs[:return] = true
|
55
56
|
|
56
57
|
# Start tracing
|
57
|
-
::Instana.tracer.
|
58
|
+
span = ::Instana.tracer.start_span(:rack, attributes: {:on_trace_start => 1})
|
58
59
|
assert_equal true, ::Instana.tracer.tracing?
|
59
60
|
|
60
61
|
# Now the automagic
|
61
|
-
::Instana.tracer.
|
62
|
+
::Instana.tracer.in_span(:custom_span, attributes: kvs) do
|
62
63
|
answer = 42 * 1
|
63
64
|
active_span = ::Instana.tracer.current_span
|
64
65
|
active_span.set_tag(:answer, answer)
|
65
66
|
|
66
67
|
# And now nested automagic
|
67
|
-
::Instana.tracer.
|
68
|
+
::Instana.tracer.in_span(:custom_span2, attributes: kvs) do
|
68
69
|
was_here = 'stan'
|
69
70
|
active_span = ::Instana.tracer.current_span
|
70
71
|
active_span.set_tag(:was_here, was_here)
|
@@ -72,7 +73,8 @@ class CustomTracingTest < Minitest::Test
|
|
72
73
|
end
|
73
74
|
|
74
75
|
# End tracing
|
75
|
-
|
76
|
+
span.add_attributes({:on_trace_end => 1})
|
77
|
+
span.finish
|
76
78
|
assert_equal false, ::Instana.tracer.tracing?
|
77
79
|
|
78
80
|
spans = ::Instana.processor.queued_spans
|
@@ -111,20 +113,23 @@ class CustomTracingTest < Minitest::Test
|
|
111
113
|
assert_equal false, ::Instana.tracer.tracing?
|
112
114
|
|
113
115
|
# Start tracing
|
114
|
-
::Instana.tracer.
|
116
|
+
span1 = ::Instana.tracer.start_span(:rack, attributes: {:on_trace_start => 1})
|
115
117
|
assert_equal true, ::Instana.tracer.tracing?
|
116
118
|
|
117
119
|
kvs = {}
|
118
120
|
kvs[:on_entry_kv] = 1
|
119
|
-
kvs[:arguments] = [[1,2,3], "test_arg", :ok]
|
121
|
+
kvs[:arguments] = [[1, 2, 3], "test_arg", :ok]
|
120
122
|
kvs[:return] = true
|
121
123
|
|
122
|
-
::Instana.tracer.
|
123
|
-
|
124
|
-
|
124
|
+
span2 = ::Instana.tracer.start_span(:custom_span, attributes: kvs)
|
125
|
+
span2.set_tags({:on_info_kv => 1})
|
126
|
+
span2.set_tags({:on_exit_kv => 1})
|
127
|
+
span2.finish
|
125
128
|
|
126
129
|
# End tracing
|
127
|
-
|
130
|
+
span1.set_tags({:on_trace_end => 1})
|
131
|
+
span1.finish
|
132
|
+
|
128
133
|
assert_equal false, ::Instana.tracer.tracing?
|
129
134
|
|
130
135
|
spans = ::Instana.processor.queued_spans
|
@@ -134,7 +139,7 @@ class CustomTracingTest < Minitest::Test
|
|
134
139
|
second_span = find_first_span_by_name(spans, :custom_span)
|
135
140
|
|
136
141
|
assert first_span[:ts].is_a?(Integer)
|
137
|
-
assert first_span[:ts]
|
142
|
+
assert first_span[:ts].positive?
|
138
143
|
assert first_span[:d].is_a?(Integer)
|
139
144
|
assert first_span[:d].between?(0, 5)
|
140
145
|
|
@@ -159,28 +164,30 @@ class CustomTracingTest < Minitest::Test
|
|
159
164
|
assert_equal 1, second_span[:data][:sdk][:custom][:tags][:on_exit_kv]
|
160
165
|
end
|
161
166
|
|
162
|
-
def test_custom_tracing_with_error
|
167
|
+
def test_custom_tracing_with_error # rubocop:disable Metrics/MethodLength
|
163
168
|
clear_all!
|
164
169
|
assert_equal false, ::Instana.tracer.tracing?
|
165
170
|
|
166
171
|
# Start tracing
|
167
|
-
::Instana.tracer.
|
172
|
+
span1 = ::Instana.tracer.start_span(:rack, attributes: {:on_trace_start => 1})
|
168
173
|
assert_equal true, ::Instana.tracer.tracing?
|
169
174
|
|
170
175
|
begin
|
171
176
|
kvs = {}
|
172
177
|
kvs[:on_entry_kv] = 1
|
173
|
-
kvs[:arguments] = [[1,2,3], "test_arg", :ok]
|
178
|
+
kvs[:arguments] = [[1, 2, 3], "test_arg", :ok]
|
174
179
|
kvs[:return] = true
|
175
180
|
|
176
|
-
::Instana.tracer.
|
181
|
+
span2 = ::Instana.tracer.start_span(:custom_span, attributes: kvs)
|
177
182
|
raise "custom tracing error. This is only a test"
|
178
183
|
rescue => e
|
179
|
-
|
184
|
+
span2.record_exception(e)
|
180
185
|
ensure
|
181
|
-
|
186
|
+
span2.set_tags(:on_exit_kv => 1)
|
187
|
+
span2.finish
|
182
188
|
end
|
183
|
-
|
189
|
+
span1.set_tags(:on_trace_end => 1)
|
190
|
+
span1.finish
|
184
191
|
assert_equal false, ::Instana.tracer.tracing?
|
185
192
|
|
186
193
|
spans = ::Instana.processor.queued_spans
|
@@ -190,7 +197,7 @@ class CustomTracingTest < Minitest::Test
|
|
190
197
|
second_span = find_first_span_by_name(spans, :custom_span)
|
191
198
|
|
192
199
|
assert first_span[:ts].is_a?(Integer)
|
193
|
-
assert first_span[:ts]
|
200
|
+
assert first_span[:ts].positive?
|
194
201
|
assert first_span[:d].is_a?(Integer)
|
195
202
|
assert first_span[:d].between?(0, 5)
|
196
203
|
|
@@ -202,7 +209,7 @@ class CustomTracingTest < Minitest::Test
|
|
202
209
|
assert_equal 1, first_span[:data][:on_trace_end]
|
203
210
|
|
204
211
|
assert second_span[:ts].is_a?(Integer)
|
205
|
-
assert second_span[:ts]
|
212
|
+
assert second_span[:ts].positive?
|
206
213
|
assert second_span[:d].is_a?(Integer)
|
207
214
|
assert second_span[:d].between?(0, 5)
|
208
215
|
|
@@ -11,7 +11,7 @@ class InstrumentedLoggerTest < Minitest::Test
|
|
11
11
|
def test_log_warn_error
|
12
12
|
subject = Instana::InstrumentedLogger.new('/dev/null')
|
13
13
|
|
14
|
-
Instana::Tracer.
|
14
|
+
Instana::Tracer.in_span(:test_logging) do
|
15
15
|
subject.warn('warn')
|
16
16
|
subject.debug('test')
|
17
17
|
subject.error('error')
|
@@ -13,12 +13,12 @@ class ProcessorTest < Minitest::Test
|
|
13
13
|
clear_all!
|
14
14
|
subject = Instana::Processor.new
|
15
15
|
|
16
|
-
span_context = Instana::SpanContext.new('9', '8', 0)
|
17
|
-
span = Instana::Span.new(:rack,
|
16
|
+
span_context = Instana::SpanContext.new(trace_id: '9', span_id: '8', level: 0)
|
17
|
+
span = Instana::Span.new(:rack, span_context)
|
18
18
|
span2 = Instana::Span.new(:"net-http")
|
19
19
|
|
20
|
-
subject.
|
21
|
-
subject.
|
20
|
+
subject.on_finish(span)
|
21
|
+
subject.on_finish(span2)
|
22
22
|
|
23
23
|
spans = subject.queued_spans
|
24
24
|
valid_span, = spans
|
@@ -29,7 +29,7 @@ class ProcessorTest < Minitest::Test
|
|
29
29
|
|
30
30
|
def test_queued_spans_invalid_type
|
31
31
|
subject = Instana::Processor.new
|
32
|
-
subject.
|
32
|
+
subject.on_finish(false)
|
33
33
|
|
34
34
|
assert_equal [], subject.queued_spans
|
35
35
|
end
|
@@ -39,7 +39,7 @@ class ProcessorTest < Minitest::Test
|
|
39
39
|
|
40
40
|
subject = Instana::Processor.new
|
41
41
|
span = Instana::Span.new(:rack)
|
42
|
-
subject.
|
42
|
+
subject.on_finish(span)
|
43
43
|
|
44
44
|
was_invoked = false
|
45
45
|
|
@@ -5,17 +5,17 @@ require 'test_helper'
|
|
5
5
|
|
6
6
|
class SpanContextTest < Minitest::Test
|
7
7
|
def test_to_hash
|
8
|
-
subject = Instana::SpanContext.new('trace', 'span')
|
8
|
+
subject = Instana::SpanContext.new(trace_id: 'trace', span_id: 'span')
|
9
9
|
assert_equal({trace_id: 'trace', span_id: 'span'}, subject.to_hash)
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_invalid
|
13
|
-
subject = Instana::SpanContext.new(nil, nil)
|
13
|
+
subject = Instana::SpanContext.new(trace_id: nil, span_id: nil)
|
14
14
|
refute subject.valid?
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_flags_level_zero
|
18
|
-
subject = Instana::SpanContext.new('trace', 'span', 0, {external_state: 'cn=test'})
|
18
|
+
subject = Instana::SpanContext.new(trace_id: 'trace', span_id: 'span', level: 0, baggage: {external_state: 'cn=test'})
|
19
19
|
assert_equal '00-000000000000000000000000000trace-000000000000span-00', subject.trace_parent_header
|
20
20
|
assert_equal 'cn=test', subject.trace_state_header
|
21
21
|
end
|
@@ -39,15 +39,15 @@ class SpanTest < Minitest::Test
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_span_from_contetx
|
42
|
-
context = Instana::SpanContext.new('test', 'test', 0)
|
43
|
-
span = Instana::Span.new(:test,
|
42
|
+
context = Instana::SpanContext.new(trace_id: 'test', span_id: 'test', level: 0)
|
43
|
+
span = Instana::Span.new(:test, context)
|
44
44
|
|
45
45
|
assert_equal 'test', span.parent_id
|
46
46
|
assert_equal 'test', span.trace_id
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_span_from_contetx_invalid
|
50
|
-
context = Instana::SpanContext.new(nil, nil, 1)
|
50
|
+
context = Instana::SpanContext.new(trace_id: nil, span_id: nil, level: 1)
|
51
51
|
span = Instana::Span.new(:test, parent_ctx: context)
|
52
52
|
|
53
53
|
assert_nil span.parent_id
|
@@ -93,16 +93,16 @@ class SpanTest < Minitest::Test
|
|
93
93
|
span = Instana::Span.new(:activerecord)
|
94
94
|
span.set_tag(:activerecord, {})
|
95
95
|
|
96
|
-
span.
|
97
|
-
span.
|
96
|
+
span.record_exception(StandardError.new('Test1'))
|
97
|
+
span.record_exception(StandardError.new('Test2'))
|
98
98
|
|
99
99
|
assert_equal 2, span[:ec]
|
100
100
|
assert_equal 'Test2', span[:data][:activerecord][:error]
|
101
101
|
end
|
102
102
|
|
103
|
-
def
|
103
|
+
def test_record_exception_nil
|
104
104
|
span = Instana::Span.new(:activerecord)
|
105
|
-
span.
|
105
|
+
span.record_exception(nil)
|
106
106
|
|
107
107
|
assert_equal 1, span[:ec]
|
108
108
|
end
|
@@ -8,7 +8,7 @@ class TracerAsyncTest < Minitest::Test
|
|
8
8
|
clear_all!
|
9
9
|
|
10
10
|
# Start tracing
|
11
|
-
::Instana.tracer.
|
11
|
+
::Instana.tracer.start_span(:rack, attributes: {:rack_start_kv => 1})
|
12
12
|
|
13
13
|
# Start an asynchronous span
|
14
14
|
span = ::Instana.tracer.log_async_entry(:my_async_op, { :entry_kv => 1})
|
@@ -54,26 +54,33 @@ class TracerAsyncTest < Minitest::Test
|
|
54
54
|
clear_all!
|
55
55
|
|
56
56
|
# Start tracing
|
57
|
-
::Instana.tracer.
|
57
|
+
span = ::Instana.tracer.start_span(:rack, attributes: {:rack_start_kv => 1})
|
58
58
|
|
59
59
|
t_context = ::Instana.tracer.context
|
60
60
|
refute_nil t_context.trace_id
|
61
61
|
refute_nil t_context.span_id
|
62
62
|
|
63
63
|
Thread.new do
|
64
|
-
::Instana.
|
65
|
-
|
64
|
+
span1 = ::Instana::Trace.with_span(OpenTelemetry::Trace.non_recording_span(t_context)) do
|
65
|
+
::Instana.tracer.start_span(:async_thread, attributes: { :async_start => 1 })
|
66
|
+
end
|
67
|
+
span2 = ::Instana::Trace.with_span(span1) do
|
68
|
+
::Instana.tracer.start_span(:sleepy_time, attributes: { :tired => 1 })
|
69
|
+
end
|
70
|
+
|
66
71
|
# Sleep beyond the end of this root trace
|
67
72
|
sleep 0.5
|
68
|
-
|
69
|
-
|
73
|
+
span2.set_tags({ :wake_up => 1})
|
74
|
+
span2.finish
|
75
|
+
span1.set_tags({:async_end => 1})
|
76
|
+
span1.finish
|
70
77
|
end
|
71
|
-
|
72
78
|
# Current span should still be rack
|
73
79
|
assert_equal :rack, ::Instana.tracer.current_span.name
|
74
|
-
|
80
|
+
span.set_tags({:rack_end_kv => 1})
|
81
|
+
span.finish
|
75
82
|
# End tracing
|
76
|
-
::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
|
83
|
+
# ::Instana.tracer.log_end(:rack, {:rack_end_kv => 1})
|
77
84
|
|
78
85
|
assert_equal false, ::Instana.tracer.tracing?
|
79
86
|
|
@@ -106,15 +113,14 @@ class TracerAsyncTest < Minitest::Test
|
|
106
113
|
assert async_span2[:d]
|
107
114
|
assert_equal 1, async_span2[:data][:sdk][:custom][:tags][:tired]
|
108
115
|
assert_equal 1, async_span2[:data][:sdk][:custom][:tags][:wake_up]
|
109
|
-
|
110
116
|
# Validate linkage
|
111
117
|
# All spans have the same trace ID
|
112
|
-
assert rack_span[:t]==async_span1[:t] && async_span1[:t]==async_span2[:t]
|
118
|
+
assert rack_span[:t] == async_span1[:t] && async_span1[:t] == async_span2[:t]
|
113
119
|
|
114
120
|
assert_equal async_span2[:p], async_span1[:s]
|
115
121
|
assert_equal async_span1[:p], rack_span[:s]
|
116
122
|
|
117
|
-
assert rack_span[:t]
|
123
|
+
assert rack_span[:t] == rack_span[:s]
|
118
124
|
assert async_span1[:t] != async_span1[:s]
|
119
125
|
assert async_span2[:t] != async_span2[:s]
|
120
126
|
end
|
@@ -123,15 +129,19 @@ class TracerAsyncTest < Minitest::Test
|
|
123
129
|
clear_all!
|
124
130
|
|
125
131
|
# Start tracing
|
126
|
-
::Instana.tracer.
|
132
|
+
span = ::Instana.tracer.start_span(:rack, attributes: {:rack_start_kv => 1})
|
127
133
|
|
128
134
|
# Start three asynchronous spans
|
129
|
-
span1 = ::Instana.
|
130
|
-
|
131
|
-
|
135
|
+
span1, span2, span3 = ::Instana::Trace.with_span(span) do
|
136
|
+
span1 = ::Instana.tracer.start_span(:my_async_op1, attributes: { :entry_kv => 1})
|
137
|
+
span2 = ::Instana.tracer.start_span(:my_async_op2, attributes: { :entry_kv => 2})
|
138
|
+
span3 = ::Instana.tracer.start_span(:my_async_op3, attributes: { :entry_kv => 3})
|
139
|
+
return span1, span2, span3
|
140
|
+
end
|
132
141
|
|
142
|
+
# Context awareness when using Opentelemetry is done through Opentelemetry::Context so the below test is invalid
|
133
143
|
# Current span should still be rack
|
134
|
-
assert_equal :rack, ::Instana.tracer.current_span.name
|
144
|
+
# assert_equal :rack, ::Instana.tracer.current_span.name
|
135
145
|
|
136
146
|
# Log info to the async spans (out of order)
|
137
147
|
span2.set_tags({ :info_kv => 2 })
|
@@ -139,8 +149,8 @@ class TracerAsyncTest < Minitest::Test
|
|
139
149
|
span3.set_tags({ :info_kv => 3 })
|
140
150
|
|
141
151
|
# Log out of order errors to the async spans
|
142
|
-
span3.
|
143
|
-
span2.
|
152
|
+
span3.record_exception(Exception.new("Async span 3"))
|
153
|
+
span2.record_exception(Exception.new("Async span 3"))
|
144
154
|
|
145
155
|
# End two out of order asynchronous spans
|
146
156
|
span3.set_tags({ :exit_kv => 3 })
|
@@ -148,14 +158,16 @@ class TracerAsyncTest < Minitest::Test
|
|
148
158
|
span2.set_tags({ :exit_kv => 2 })
|
149
159
|
span2.close
|
150
160
|
|
161
|
+
# Context awareness when using Opentelemetry is done through Opentelemetry::Context so the below test is invalid
|
151
162
|
# Current span should still be rack
|
152
|
-
assert_equal :rack, ::Instana.tracer.current_span.name
|
163
|
+
# assert_equal :rack, ::Instana.tracer.current_span.name
|
153
164
|
|
154
165
|
# End tracing
|
155
|
-
|
166
|
+
span.set_tags({:rack_end_kv => 1})
|
167
|
+
span.finish
|
156
168
|
|
157
169
|
# Log an error to and close out the remaining async span after the parent trace has finished
|
158
|
-
span1.
|
170
|
+
span1.record_exception(Exception.new("Async span 1"))
|
159
171
|
span1.set_tags({ :exit_kv => 1 })
|
160
172
|
span1.close
|
161
173
|
|
@@ -201,12 +213,12 @@ class TracerAsyncTest < Minitest::Test
|
|
201
213
|
|
202
214
|
def test_async_helpers
|
203
215
|
clear_all!
|
204
|
-
::Instana.tracer.
|
216
|
+
::Instana.tracer.start_span(:rack)
|
205
217
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
218
|
+
span1 = ::Instana.tracer.start_span(:async, attributes: {})
|
219
|
+
span1.set_tags({a: 1})
|
220
|
+
span1.record_exception(StandardError.new('Error'))
|
221
|
+
span1.finish
|
210
222
|
|
211
223
|
spans = ::Instana.processor.queued_spans
|
212
224
|
span, = spans
|
@@ -217,10 +229,11 @@ class TracerAsyncTest < Minitest::Test
|
|
217
229
|
|
218
230
|
def test_async_helpers_tag_exit
|
219
231
|
clear_all!
|
220
|
-
::Instana.tracer.
|
232
|
+
::Instana.tracer.start_span(:rack)
|
221
233
|
|
222
|
-
|
223
|
-
|
234
|
+
span1 = ::Instana.tracer.start_span(:async, attributes: {})
|
235
|
+
span1.set_tags({a: 1})
|
236
|
+
span1.finish
|
224
237
|
|
225
238
|
spans = ::Instana.processor.queued_spans
|
226
239
|
span, = spans
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2025
|
2
|
+
# (c) Copyright Instana Inc. 2025
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
require 'instana/trace/tracer_provider'
|
6
|
+
require 'instana/trace/export'
|
7
|
+
|
8
|
+
class TracerProviderTest < Minitest::Test
|
9
|
+
def setup
|
10
|
+
@tracer_provider = Instana.tracer_provider
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_tracer
|
14
|
+
# This tests the global tracer is the same as tracer from tracer_provider
|
15
|
+
assert_equal Instana.tracer, @tracer_provider.tracer("instana_tracer")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_shutdown_with_timeout
|
19
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
20
|
+
@tracer_provider.add_span_processor(DummyProcessor.new)
|
21
|
+
timeout = 10
|
22
|
+
result = @tracer_provider.shutdown(timeout: timeout)
|
23
|
+
assert_equal Instana::Trace::Export::SUCCESS, result
|
24
|
+
@span_processors = @tracer_provider.instance_variable_get(:@span_processors)
|
25
|
+
assert_equal 1, @tracer_provider.instance_variable_get(:@span_processors).length
|
26
|
+
assert_equal [Instana::Trace::Export::SUCCESS], @tracer_provider.instance_variable_get(:@span_processors).map(&:shutdown)
|
27
|
+
assert @tracer_provider.instance_variable_get(:@stopped)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_shutdown_without_timeout
|
31
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
32
|
+
@tracer_provider.add_span_processor(DummyProcessor.new)
|
33
|
+
# @tracer = @tracer_provider.tracer('test_shutdown_without_timeout')
|
34
|
+
result = @tracer_provider.shutdown
|
35
|
+
assert_equal Instana::Trace::Export::SUCCESS, result
|
36
|
+
|
37
|
+
assert_equal 1, @tracer_provider.instance_variable_get(:@span_processors).length
|
38
|
+
assert_equal [Instana::Trace::Export::SUCCESS], @tracer_provider.instance_variable_get(:@span_processors).map(&:shutdown)
|
39
|
+
assert @tracer_provider.instance_variable_get(:@stopped)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_shutdown_called_multiple_times
|
43
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
44
|
+
@tracer_provider.add_span_processor(DummyProcessor.new)
|
45
|
+
# @tracer = @tracer_provider.tracer('test_shutdown_called_multiple_times')
|
46
|
+
|
47
|
+
result1 = @tracer_provider.shutdown
|
48
|
+
result2 = @tracer_provider.shutdown
|
49
|
+
|
50
|
+
assert_equal Instana::Trace::Export::SUCCESS, result1
|
51
|
+
assert_equal Instana::Trace::Export::FAILURE, result2
|
52
|
+
|
53
|
+
assert_equal 1, @tracer_provider.instance_variable_get(:@span_processors).length
|
54
|
+
assert_equal [Instana::Trace::Export::SUCCESS], @tracer_provider.instance_variable_get(:@span_processors).map(&:shutdown)
|
55
|
+
assert @tracer_provider.instance_variable_get(:@stopped)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_shutdown_with_zero_timeout
|
59
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
60
|
+
@tracer_provider.add_span_processor(DummyProcessor.new)
|
61
|
+
# @tracer = @tracer_provider.tracer('test_shutdown_with_zero_timeout')
|
62
|
+
timeout = 0
|
63
|
+
result = @tracer_provider.shutdown(timeout: timeout)
|
64
|
+
assert_equal Instana::Trace::Export::TIMEOUT, result
|
65
|
+
|
66
|
+
assert_equal 1, @tracer_provider.instance_variable_get(:@span_processors).length
|
67
|
+
assert_equal [Instana::Trace::Export::SUCCESS], @tracer_provider.instance_variable_get(:@span_processors).map(&:shutdown)
|
68
|
+
assert @tracer_provider.instance_variable_get(:@stopped)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_force_flush_with_timeout
|
72
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
73
|
+
@tracer_provider.add_span_processor(DummyProcessor.new)
|
74
|
+
timeout = 10
|
75
|
+
result = @tracer_provider.force_flush(timeout: timeout)
|
76
|
+
assert_equal Instana::Trace::Export::SUCCESS, result
|
77
|
+
@span_processors = @tracer_provider.instance_variable_get(:@span_processors)
|
78
|
+
assert_equal 1, @tracer_provider.instance_variable_get(:@span_processors).length
|
79
|
+
assert_equal [Instana::Trace::Export::SUCCESS], @tracer_provider.instance_variable_get(:@span_processors).map(&:shutdown)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_force_flush_without_timeout
|
83
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
84
|
+
@tracer_provider.add_span_processor(DummyProcessor.new)
|
85
|
+
result = @tracer_provider.force_flush
|
86
|
+
assert_equal Instana::Trace::Export::SUCCESS, result
|
87
|
+
|
88
|
+
assert_equal 1, @tracer_provider.instance_variable_get(:@span_processors).length
|
89
|
+
assert_equal [Instana::Trace::Export::SUCCESS], @tracer_provider.instance_variable_get(:@span_processors).map(&:shutdown)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_force_flush_with_zero_timeout
|
93
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
94
|
+
@tracer_provider.add_span_processor(DummyProcessor.new)
|
95
|
+
timeout = 0
|
96
|
+
result = @tracer_provider.force_flush(timeout: timeout)
|
97
|
+
assert_equal Instana::Trace::Export::TIMEOUT, result
|
98
|
+
|
99
|
+
assert_equal 1, @tracer_provider.instance_variable_get(:@span_processors).length
|
100
|
+
assert_equal [Instana::Trace::Export::SUCCESS], @tracer_provider.instance_variable_get(:@span_processors).map(&:shutdown)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_add_span_processor_after_shutdown
|
104
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
105
|
+
@tracer_provider.add_span_processor(DummyProcessor.new)
|
106
|
+
@tracer_provider.shutdown
|
107
|
+
result = @tracer_provider.add_span_processor(DummyProcessor.new)
|
108
|
+
assert_nil result
|
109
|
+
# No new span processor was added as tracer_provider is stopped
|
110
|
+
assert_equal 1, @tracer_provider.instance_variable_get(:@span_processors).length
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_internal_start_span_untraced
|
114
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
115
|
+
Minitest::Mock.new
|
116
|
+
result = @tracer_provider.internal_start_span('test_span', 'kind', {}, [], Time.now, nil, @instrumentation_scope)
|
117
|
+
assert_instance_of(Instana::Span, result)
|
118
|
+
# Todo add proper testcase
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_internal_start_span_traced
|
122
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
123
|
+
Minitest::Mock.new
|
124
|
+
result = @tracer_provider.internal_start_span('test_span', 'kind', {}, [], Time.now, nil, @instrumentation_scope)
|
125
|
+
assert_instance_of(Instana::Span, result)
|
126
|
+
# Todo add proper testcase
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_internal_start_span_stopped
|
130
|
+
@tracer_provider = ::Instana::Trace::TracerProvider.new
|
131
|
+
Minitest::Mock.new
|
132
|
+
result = @tracer_provider.internal_start_span('test_span', 'kind', {}, [], Time.now, nil, @instrumentation_scope)
|
133
|
+
assert_instance_of(Instana::Span, result)
|
134
|
+
# Todo add proper testcase
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class DummyProcessor
|
139
|
+
def initialize; end
|
140
|
+
|
141
|
+
def shutdown(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
|
142
|
+
Instana::Trace::Export::SUCCESS
|
143
|
+
end
|
144
|
+
|
145
|
+
def force_flush(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
|
146
|
+
Instana::Trace::Export::SUCCESS
|
147
|
+
end
|
148
|
+
end
|