instana 1.195.2 → 1.197.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/.rubocop.yml +6 -2
- data/Rakefile +1 -1
- data/instana.gemspec +3 -7
- data/lib/instana.rb +3 -0
- data/lib/instana/activator.rb +2 -0
- data/lib/instana/backend/agent.rb +60 -0
- data/lib/instana/backend/gc_snapshot.rb +41 -0
- data/lib/instana/backend/host_agent.rb +74 -0
- data/lib/instana/backend/host_agent_activation_observer.rb +97 -0
- data/lib/instana/backend/host_agent_lookup.rb +57 -0
- data/lib/instana/backend/host_agent_reporting_observer.rb +106 -0
- data/lib/instana/backend/process_info.rb +64 -0
- data/lib/instana/backend/request_client.rb +73 -0
- data/lib/instana/backend/serverless_agent.rb +118 -0
- data/lib/instana/base.rb +8 -27
- data/lib/instana/config.rb +8 -22
- data/lib/instana/instrumentation/excon.rb +17 -8
- data/lib/instana/instrumentation/instrumented_request.rb +62 -7
- data/lib/instana/instrumentation/net-http.rb +7 -5
- data/lib/instana/instrumentation/rack.rb +12 -7
- data/lib/instana/logger_delegator.rb +31 -0
- data/lib/instana/{opentracing → open_tracing}/carrier.rb +0 -0
- data/lib/instana/open_tracing/instana_tracer.rb +99 -0
- data/lib/instana/secrets.rb +6 -2
- data/lib/instana/setup.rb +20 -11
- data/lib/instana/snapshot/deltable.rb +25 -0
- data/lib/instana/snapshot/docker_container.rb +151 -0
- data/lib/instana/snapshot/fargate_container.rb +88 -0
- data/lib/instana/snapshot/fargate_process.rb +67 -0
- data/lib/instana/snapshot/fargate_task.rb +72 -0
- data/lib/instana/snapshot/lambda_function.rb +36 -0
- data/lib/instana/snapshot/ruby_process.rb +48 -0
- data/lib/instana/tracer.rb +25 -143
- data/lib/instana/tracing/processor.rb +14 -22
- data/lib/instana/tracing/span.rb +31 -34
- data/lib/instana/tracing/span_context.rb +15 -10
- data/lib/instana/util.rb +8 -69
- data/lib/instana/version.rb +1 -1
- data/lib/opentracing.rb +26 -3
- data/test/backend/agent_test.rb +54 -0
- data/test/backend/gc_snapshot_test.rb +11 -0
- data/test/backend/host_agent_activation_observer_test.rb +72 -0
- data/test/backend/host_agent_lookup_test.rb +78 -0
- data/test/backend/host_agent_reporting_observer_test.rb +192 -0
- data/test/backend/host_agent_test.rb +47 -0
- data/test/backend/process_info_test.rb +63 -0
- data/test/backend/request_client_test.rb +39 -0
- data/test/backend/serverless_agent_test.rb +73 -0
- data/test/config_test.rb +10 -0
- data/test/instana_test.rb +11 -4
- data/test/instrumentation/excon_test.rb +15 -1
- data/test/instrumentation/rack_instrumented_request_test.rb +5 -2
- data/test/instrumentation/rack_test.rb +2 -14
- data/test/secrets_test.rb +41 -22
- data/test/snapshot/deltable_test.rb +17 -0
- data/test/snapshot/docker_container_test.rb +82 -0
- data/test/snapshot/fargate_container_test.rb +82 -0
- data/test/snapshot/fargate_process_test.rb +35 -0
- data/test/snapshot/fargate_task_test.rb +49 -0
- data/test/snapshot/ruby_process_test.rb +14 -0
- data/test/support/mock_timer.rb +20 -0
- data/test/test_helper.rb +16 -4
- data/test/tracing/custom_test.rb +1 -3
- data/test/tracing/id_management_test.rb +4 -0
- data/test/tracing/opentracing_test.rb +15 -2
- data/test/tracing/processor_test.rb +58 -0
- data/test/tracing/span_context_test.rb +21 -0
- data/test/tracing/span_test.rb +136 -0
- data/test/tracing/tracer_async_test.rb +29 -0
- data/test/tracing/tracer_test.rb +82 -16
- data/test/util_test.rb +10 -0
- metadata +71 -43
- data/lib/instana/agent.rb +0 -508
- data/lib/instana/agent/helpers.rb +0 -87
- data/lib/instana/agent/hooks.rb +0 -44
- data/lib/instana/agent/tasks.rb +0 -51
- data/lib/instana/collector.rb +0 -119
- data/lib/instana/collectors/gc.rb +0 -60
- data/lib/instana/collectors/memory.rb +0 -37
- data/lib/instana/collectors/thread.rb +0 -33
- data/lib/instana/eum/eum-test.js.erb +0 -17
- data/lib/instana/eum/eum.js.erb +0 -17
- data/lib/instana/helpers.rb +0 -47
- data/lib/instana/opentracing/tracer.rb +0 -21
- data/lib/instana/thread_local.rb +0 -18
- data/lib/oj_check.rb +0 -19
- data/test/agent/agent_test.rb +0 -151
@@ -0,0 +1,82 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class FargateContainerTest < Minitest::Test
|
7
|
+
def test_snapshot_observed
|
8
|
+
container = JSON.parse(File.read('test/support/ecs/task.json'))['Containers'].first
|
9
|
+
subject = Instana::Snapshot::FargateContainer.new(container, metadata_uri: 'https://10.10.10.10:8080/v3')
|
10
|
+
|
11
|
+
stub_request(:get, 'https://10.10.10.10:8080/v3')
|
12
|
+
.to_return(status: 200, body: File.read('test/support/ecs/container.json'))
|
13
|
+
|
14
|
+
snapshot = subject.snapshot
|
15
|
+
|
16
|
+
assert_equal Instana::Snapshot::FargateContainer::ID, snapshot[:name]
|
17
|
+
assert_equal 'arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3::~internal~ecs~pause', snapshot[:entityId]
|
18
|
+
|
19
|
+
assert_equal "731a0d6a3b4210e2448339bc7015aaa79bfe4fa256384f4102db86ef94cbbc4c", snapshot[:data][:dockerId]
|
20
|
+
assert_equal "ecs-nginx-5-internalecspause-acc699c0cbf2d6d11700", snapshot[:data][:dockerName]
|
21
|
+
assert_equal "~internal~ecs~pause", snapshot[:data][:containerName]
|
22
|
+
assert_equal "amazon/amazon-ecs-pause:0.1.0", snapshot[:data][:image]
|
23
|
+
assert_equal "", snapshot[:data][:imageId]
|
24
|
+
assert_equal "arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3", snapshot[:data][:taskArn]
|
25
|
+
assert_nil snapshot[:data][:taskDefinition]
|
26
|
+
assert_nil snapshot[:data][:taskDefinitionVersion]
|
27
|
+
assert_equal "default", snapshot[:data][:clusterArn]
|
28
|
+
assert_equal "RESOURCES_PROVISIONED", snapshot[:data][:desiredStatus]
|
29
|
+
assert_equal "RESOURCES_PROVISIONED", snapshot[:data][:knownStatus]
|
30
|
+
assert_nil snapshot[:data][:ports]
|
31
|
+
assert_equal({:cpu => 0, :memory => 0}, snapshot[:data][:limits])
|
32
|
+
assert_equal "2018-02-01T20:55:08.366329616Z", snapshot[:data][:createdAt]
|
33
|
+
assert_equal "2018-02-01T20:55:09.058354915Z", snapshot[:data][:startedAt]
|
34
|
+
|
35
|
+
assert_nil subject.source
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_snapshot_current
|
39
|
+
container = JSON.parse(File.read('test/support/ecs/task.json'))['Containers'].last
|
40
|
+
subject = Instana::Snapshot::FargateContainer.new(container, metadata_uri: 'https://10.10.10.10:8080/v3')
|
41
|
+
|
42
|
+
stub_request(:get, 'https://10.10.10.10:8080/v3')
|
43
|
+
.to_return(status: 200, body: File.read('test/support/ecs/container.json'))
|
44
|
+
|
45
|
+
snapshot = subject.snapshot
|
46
|
+
|
47
|
+
assert_equal Instana::Snapshot::FargateContainer::ID, snapshot[:name]
|
48
|
+
assert_equal 'arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3::nginx-curl', snapshot[:entityId]
|
49
|
+
|
50
|
+
assert_equal "43481a6ce4842eec8fe72fc28500c6b52edcc0917f105b83379f88cac1ff3946", snapshot[:data][:dockerId]
|
51
|
+
assert_equal "ecs-nginx-5-nginx-curl-ccccb9f49db0dfe0d901", snapshot[:data][:dockerName]
|
52
|
+
assert_equal "nginx-curl", snapshot[:data][:containerName]
|
53
|
+
assert_equal "nrdlngr/nginx-curl", snapshot[:data][:image]
|
54
|
+
assert_equal "sha256:2e00ae64383cfc865ba0a2ba37f61b50a120d2d9378559dcd458dc0de47bc165", snapshot[:data][:imageId]
|
55
|
+
assert_equal "arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3", snapshot[:data][:taskArn]
|
56
|
+
assert_nil snapshot[:data][:taskDefinition]
|
57
|
+
assert_nil snapshot[:data][:taskDefinitionVersion]
|
58
|
+
assert_equal "default", snapshot[:data][:clusterArn]
|
59
|
+
assert_equal "RUNNING", snapshot[:data][:desiredStatus]
|
60
|
+
assert_equal "RUNNING", snapshot[:data][:knownStatus]
|
61
|
+
assert_nil snapshot[:data][:ports]
|
62
|
+
assert_equal({:cpu => 512, :memory => 512}, snapshot[:data][:limits])
|
63
|
+
assert_equal "2018-02-01T20:55:10.554941919Z", snapshot[:data][:createdAt]
|
64
|
+
assert_equal "2018-02-01T20:55:11.064236631Z", snapshot[:data][:startedAt]
|
65
|
+
assert_equal true, snapshot[:data][:instrumented]
|
66
|
+
assert_equal "ruby", snapshot[:data][:runtime]
|
67
|
+
|
68
|
+
assert_equal({hl: true, cp: "aws", e: "arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3::nginx-curl"}, subject.source)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_snapshot_error
|
72
|
+
stub_request(:get, 'https://10.10.10.10:8080/v3')
|
73
|
+
.to_return(status: 500)
|
74
|
+
|
75
|
+
container = JSON.parse(File.read('test/support/ecs/task.json'))['Containers'].first
|
76
|
+
subject = Instana::Snapshot::FargateContainer.new(container, metadata_uri: 'https://10.10.10.10:8080/v3')
|
77
|
+
|
78
|
+
assert_raises do
|
79
|
+
subject.snapshot
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class FargateProcessTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@subject = Instana::Snapshot::FargateProcess.new(metadata_uri: 'https://10.10.10.10:8080/v3')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_snapshot
|
12
|
+
stub_request(:get, 'https://10.10.10.10:8080/v3')
|
13
|
+
.to_return(status: 200, body: File.read('test/support/ecs/container.json'))
|
14
|
+
stub_request(:get, 'https://10.10.10.10:8080/v3/task')
|
15
|
+
.to_return(status: 200, body: File.read('test/support/ecs/task.json'))
|
16
|
+
|
17
|
+
snapshot = @subject.snapshot
|
18
|
+
|
19
|
+
assert_equal Instana::Snapshot::FargateProcess::ID, snapshot[:name]
|
20
|
+
assert_equal Process.pid.to_s, snapshot[:entityId]
|
21
|
+
|
22
|
+
assert_equal 'docker', snapshot[:data][:containerType]
|
23
|
+
assert_equal '43481a6ce4842eec8fe72fc28500c6b52edcc0917f105b83379f88cac1ff3946', snapshot[:data][:container]
|
24
|
+
assert_equal 'arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3', snapshot[:data][:'com.instana.plugin.host.name']
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_snapshot_error
|
28
|
+
stub_request(:get, 'https://10.10.10.10:8080/v3')
|
29
|
+
.to_return(status: 500)
|
30
|
+
|
31
|
+
assert_raises do
|
32
|
+
@subject.snapshot
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class FargateTaskTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@subject = Instana::Snapshot::FargateTask.new(metadata_uri: 'https://10.10.10.10:8080/v3')
|
9
|
+
|
10
|
+
ENV['INSTANA_ZONE'] = 'test'
|
11
|
+
ENV['INSTANA_TAGS'] = 'test=a,b,c'
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
ENV['INSTANA_ZONE'] = nil
|
16
|
+
ENV['INSTANA_TAGS'] = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_snapshot
|
20
|
+
stub_request(:get, 'https://10.10.10.10:8080/v3/task')
|
21
|
+
.to_return(status: 200, body: File.read('test/support/ecs/task.json'))
|
22
|
+
|
23
|
+
snapshot = @subject.snapshot
|
24
|
+
|
25
|
+
assert_equal Instana::Snapshot::FargateTask::ID, snapshot[:name]
|
26
|
+
assert_equal 'arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3', snapshot[:entityId]
|
27
|
+
|
28
|
+
assert_equal "arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3", snapshot[:data][:taskArn]
|
29
|
+
assert_equal "default", snapshot[:data][:clusterArn]
|
30
|
+
assert_equal "nginx", snapshot[:data][:taskDefinition]
|
31
|
+
assert_equal "5", snapshot[:data][:taskDefinitionVersion]
|
32
|
+
assert_equal "us-east-2b", snapshot[:data][:availabilityZone]
|
33
|
+
assert_equal "RUNNING", snapshot[:data][:desiredStatus]
|
34
|
+
assert_equal "RUNNING", snapshot[:data][:knownStatus]
|
35
|
+
assert_equal "2018-02-01T20:55:09.372495529Z", snapshot[:data][:pullStartedAt]
|
36
|
+
assert_equal "2018-02-01T20:55:10.552018345Z", snapshot[:data][:pullStoppedAt]
|
37
|
+
assert_equal "test", snapshot[:data][:instanaZone]
|
38
|
+
assert_equal({"test" => "a", "b" => nil, "c" => nil}, snapshot[:data][:tags])
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_snapshot_error
|
42
|
+
stub_request(:get, 'https://10.10.10.10:8080/v3/task')
|
43
|
+
.to_return(status: 500)
|
44
|
+
|
45
|
+
assert_raises do
|
46
|
+
@subject.snapshot
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class RubyProcessTest < Minitest::Test
|
7
|
+
def test_snapshot
|
8
|
+
subject = Instana::Snapshot::RubyProcess.new
|
9
|
+
snapshot = subject.snapshot
|
10
|
+
|
11
|
+
assert_equal Instana::Snapshot::RubyProcess::ID, snapshot[:name]
|
12
|
+
assert_equal Process.pid.to_s, snapshot[:entityId]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
class MockTimer
|
5
|
+
attr_reader :opts, :block, :running
|
6
|
+
|
7
|
+
def initialize(*args, &blk)
|
8
|
+
@opts = args.first
|
9
|
+
@block = blk
|
10
|
+
@running = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def shutdown
|
14
|
+
@running = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute
|
18
|
+
@running = true
|
19
|
+
end
|
20
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -10,11 +10,22 @@ begin
|
|
10
10
|
SimpleCov.start do
|
11
11
|
enable_coverage :branch
|
12
12
|
|
13
|
-
add_group 'Frameworks', 'lib/instana/frameworks'
|
14
|
-
add_group 'Instrumentation', 'lib/instana/instrumentation'
|
15
|
-
|
16
13
|
add_filter %r{^/test/}
|
17
14
|
|
15
|
+
add_group(
|
16
|
+
'In Process Collector',
|
17
|
+
[%r{lib/instana/(agent|backend|tracing|collectors|open_tracing|snapshot)}, %r{lib/instana/[^/]+\.rb}]
|
18
|
+
)
|
19
|
+
|
20
|
+
if ENV['APPRAISAL_INITIALIZED']
|
21
|
+
add_group(
|
22
|
+
'Instrumentation',
|
23
|
+
%r{lib/instana/(activators|frameworks|instrumentation)}
|
24
|
+
)
|
25
|
+
else
|
26
|
+
add_filter %r{lib/instana/(activators|frameworks|instrumentation)}
|
27
|
+
end
|
28
|
+
|
18
29
|
if ENV['CI']
|
19
30
|
formatter SimpleCov::Formatter::JSONFormatter
|
20
31
|
end
|
@@ -29,11 +40,12 @@ Bundler.require
|
|
29
40
|
require "minitest/spec"
|
30
41
|
require "minitest/autorun"
|
31
42
|
require "minitest/reporters"
|
43
|
+
require 'fakefs/safe'
|
32
44
|
|
33
45
|
require 'webmock/minitest'
|
34
46
|
# Webmock: Whitelist local IPs
|
35
47
|
WebMock.disable_net_connect!(
|
36
|
-
allow: ->(uri) { %w[localhost 127.0.0.1 172.17.0.1 172.0.12.100].include?(uri.host) }
|
48
|
+
allow: ->(uri) { %w[localhost 127.0.0.1 172.17.0.1 172.0.12.100].include?(uri.host) && ENV.key?('APPRAISAL_INITIALIZED') }
|
37
49
|
)
|
38
50
|
|
39
51
|
Dir['test/support/*.rb'].each { |f| load(f) }
|
data/test/tracing/custom_test.rb
CHANGED
@@ -39,9 +39,7 @@ class CustomTracingTest < Minitest::Test
|
|
39
39
|
assert_equal :entry, first_span[:data][:sdk][:type]
|
40
40
|
|
41
41
|
assert first_span.key?(:f)
|
42
|
-
|
43
|
-
assert first_span[:f].key?(:h)
|
44
|
-
assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
|
42
|
+
assert_equal ::Instana.agent.source, first_span[:f]
|
45
43
|
end
|
46
44
|
|
47
45
|
def test_custom_tracing_with_args
|
@@ -34,8 +34,6 @@ module Instana
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
OpenTracing.global_tracer = ::Instana.tracer
|
38
|
-
|
39
37
|
class OpenTracerTest < Minitest::Test
|
40
38
|
include Rack::Test::Methods
|
41
39
|
|
@@ -60,6 +58,8 @@ class OpenTracerTest < Minitest::Test
|
|
60
58
|
assert OpenTracing.global_tracer.respond_to?(:inject)
|
61
59
|
assert OpenTracing.global_tracer.respond_to?(:extract)
|
62
60
|
|
61
|
+
assert OpenTracing.respond_to?(:start_span)
|
62
|
+
|
63
63
|
assert defined?(OpenTracing::Carrier)
|
64
64
|
carrier = OpenTracing::Carrier.new
|
65
65
|
assert carrier.respond_to?(:[])
|
@@ -356,4 +356,17 @@ class OpenTracerTest < Minitest::Test
|
|
356
356
|
span = OpenTracing.start_active_span(:rack)
|
357
357
|
assert_equal OpenTracing.active_span, span
|
358
358
|
end
|
359
|
+
|
360
|
+
def test_active_span_block
|
361
|
+
clear_all!
|
362
|
+
|
363
|
+
obj = OpenTracing.start_active_span(:rack) { 1 }
|
364
|
+
assert_equal 1, obj
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_span_rename
|
368
|
+
span = OpenTracing.start_active_span(:rack)
|
369
|
+
span.operation_name = 'test'
|
370
|
+
assert_equal 'test', span.name
|
371
|
+
end
|
359
372
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class ProcessorTest < Minitest::Test
|
7
|
+
def test_queued_spans_empty
|
8
|
+
subject = Instana::Processor.new
|
9
|
+
assert_equal [], subject.queued_spans
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_queued_spans_valid_level
|
13
|
+
clear_all!
|
14
|
+
subject = Instana::Processor.new
|
15
|
+
|
16
|
+
span_context = Instana::SpanContext.new('9', '8', 0)
|
17
|
+
span = Instana::Span.new(:rack, parent_ctx: span_context)
|
18
|
+
span2 = Instana::Span.new(:"net-http")
|
19
|
+
|
20
|
+
subject.add_span(span)
|
21
|
+
subject.add_span(span2)
|
22
|
+
|
23
|
+
spans = subject.queued_spans
|
24
|
+
valid_span, = spans
|
25
|
+
|
26
|
+
assert_equal 1, spans.length
|
27
|
+
assert_equal :"net-http", valid_span[:n]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_queued_spans_invalid_type
|
31
|
+
subject = Instana::Processor.new
|
32
|
+
subject.add_span(false)
|
33
|
+
|
34
|
+
assert_equal [], subject.queued_spans
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_send
|
38
|
+
ENV['INSTANA_TEST'] = nil
|
39
|
+
|
40
|
+
subject = Instana::Processor.new
|
41
|
+
span = Instana::Span.new(:rack)
|
42
|
+
subject.add_span(span)
|
43
|
+
|
44
|
+
was_invoked = false
|
45
|
+
|
46
|
+
subject.send do |spans|
|
47
|
+
was_invoked = true
|
48
|
+
rack_span, = spans
|
49
|
+
|
50
|
+
assert_equal 1, spans.length
|
51
|
+
assert_equal :rack, rack_span[:n]
|
52
|
+
end
|
53
|
+
|
54
|
+
assert was_invoked
|
55
|
+
ensure
|
56
|
+
ENV['INSTANA_TEST'] = 'true'
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class SpanContextTest < Minitest::Test
|
7
|
+
def test_to_hash
|
8
|
+
subject = Instana::SpanContext.new('trace', 'span')
|
9
|
+
assert_equal({trace_id: 'trace', span_id: 'span'}, subject.to_hash)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_invalid
|
13
|
+
subject = Instana::SpanContext.new(nil, nil)
|
14
|
+
refute subject.valid?
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_flags_level_zero
|
18
|
+
subject = Instana::SpanContext.new('trace', 'span', 0)
|
19
|
+
assert_equal '00-000000000000000000000000000trace-000000000000span-00', subject.trace_parent_header
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class SpanTest < Minitest::Test
|
7
|
+
def test_getters_setters
|
8
|
+
span = Instana::Span.new(:test)
|
9
|
+
|
10
|
+
assert_equal span[:s], span.id
|
11
|
+
assert_equal span[:t], span.trace_id
|
12
|
+
assert_equal span[:p], span.parent_id
|
13
|
+
assert_equal span[:d], span.duration
|
14
|
+
|
15
|
+
span.parent_id = 'test'
|
16
|
+
assert_equal 'test', span.parent_id
|
17
|
+
|
18
|
+
span.name = 'test'
|
19
|
+
assert_equal 'test', span[:data][:sdk][:name]
|
20
|
+
|
21
|
+
span[:t] = 'test'
|
22
|
+
assert span.key?(:t)
|
23
|
+
assert_equal 'test', span[:t]
|
24
|
+
|
25
|
+
assert span.inspect
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_builtin_span_rename
|
29
|
+
span = Instana::Span.new(:"net-http")
|
30
|
+
assert_equal :"net-http", span.name
|
31
|
+
|
32
|
+
span.name = 'test'
|
33
|
+
assert_equal 'test', span.name
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_exit_span
|
37
|
+
span = Instana::Span.new(:"net-http")
|
38
|
+
assert span.exit_span?
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_span_from_contetx
|
42
|
+
context = Instana::SpanContext.new('test', 'test', 0)
|
43
|
+
span = Instana::Span.new(:test, parent_ctx: context)
|
44
|
+
|
45
|
+
assert_equal 'test', span.parent_id
|
46
|
+
assert_equal 'test', span.trace_id
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_span_from_contetx_invalid
|
50
|
+
context = Instana::SpanContext.new(nil, nil, 1)
|
51
|
+
span = Instana::Span.new(:test, parent_ctx: context)
|
52
|
+
|
53
|
+
assert_nil span.parent_id
|
54
|
+
refute_equal context.span_id, span.trace_id
|
55
|
+
assert_equal 1, span.context.level
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_span_collect_backtraces
|
59
|
+
Instana.config[:collect_backtraces] = true
|
60
|
+
span = Instana::Span.new(:excon)
|
61
|
+
assert span[:stack]
|
62
|
+
ensure
|
63
|
+
Instana.config[:collect_backtraces] = false
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_span_stack_over_limit
|
67
|
+
def inner(depth = 50, &blk) # rubocop:disable Lint/NestedMethodDefinition
|
68
|
+
return blk.call if depth.zero?
|
69
|
+
|
70
|
+
inner(depth - 1, &blk)
|
71
|
+
end
|
72
|
+
|
73
|
+
inner do
|
74
|
+
span = Instana::Span.new(:excon)
|
75
|
+
span.add_stack(limit: 500)
|
76
|
+
assert_equal 40, span[:stack].length
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_multiple_errors
|
81
|
+
span = Instana::Span.new(:activerecord)
|
82
|
+
span.set_tag(:activerecord, {})
|
83
|
+
|
84
|
+
span.add_error(StandardError.new('Test1'))
|
85
|
+
span.add_error(StandardError.new('Test2'))
|
86
|
+
|
87
|
+
assert_equal 2, span[:ec]
|
88
|
+
assert_equal 'Test2', span[:data][:activerecord][:error]
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_add_error_nil
|
92
|
+
span = Instana::Span.new(:activerecord)
|
93
|
+
span.add_error(nil)
|
94
|
+
|
95
|
+
assert_equal 1, span[:ec]
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_set_tag_merge
|
99
|
+
span = Instana::Span.new(:excon)
|
100
|
+
span.set_tag(1024, {a: 1})
|
101
|
+
span.set_tag(1024, {b: 2})
|
102
|
+
|
103
|
+
assert_equal({'1024' => {a: 1, b: 2}}, span[:data])
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_set_tags_non_hash
|
107
|
+
span = Instana::Span.new(:excon)
|
108
|
+
assert_nil span.set_tags(0)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_tags_standard
|
112
|
+
span = Instana::Span.new(:excon)
|
113
|
+
span.set_tag(:test, {a: 1})
|
114
|
+
|
115
|
+
assert_equal({test: {a: 1}}, span.tags)
|
116
|
+
assert_equal({a: 1}, span.tags(:test))
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_log_standard
|
120
|
+
span = Instana::Span.new(:excon)
|
121
|
+
span.log(:test, Time.now, a: 1)
|
122
|
+
|
123
|
+
assert_equal({log: {a: 1}}, span.tags)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_log_error
|
127
|
+
time = Minitest::Mock.new
|
128
|
+
time.expect(:to_f, nil)
|
129
|
+
|
130
|
+
span = Instana::Span.new(:sdk)
|
131
|
+
span.log(:test, time, a: 1)
|
132
|
+
|
133
|
+
assert_equal({}, span.tags)
|
134
|
+
time.verify
|
135
|
+
end
|
136
|
+
end
|