instana 1.195.1 → 1.197.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +16 -2
- data/.rubocop.yml +6 -2
- data/Appraisals +13 -1
- data/Rakefile +1 -1
- data/docker-compose.yml +20 -0
- data/gemfiles/aws_30.gemfile +3 -0
- data/gemfiles/excon_021.gemfile +18 -0
- data/gemfiles/excon_079.gemfile +18 -0
- data/gemfiles/shoryuken_50.gemfile +19 -0
- data/instana.gemspec +3 -7
- data/lib/instana.rb +3 -0
- data/lib/instana/activator.rb +2 -0
- data/lib/instana/activators/aws_sdk_s3.rb +20 -0
- data/lib/instana/activators/aws_sdk_sns.rb +20 -0
- data/lib/instana/activators/aws_sdk_sqs.rb +20 -0
- data/lib/instana/activators/excon.rb +1 -1
- data/lib/instana/activators/shoryuken.rb +24 -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/aws_sdk_dynamodb.rb +21 -2
- data/lib/instana/instrumentation/aws_sdk_s3.rb +55 -0
- data/lib/instana/instrumentation/aws_sdk_sns.rb +29 -0
- data/lib/instana/instrumentation/aws_sdk_sqs.rb +98 -0
- data/lib/instana/instrumentation/excon.rb +19 -9
- data/lib/instana/instrumentation/instrumented_request.rb +68 -8
- data/lib/instana/instrumentation/net-http.rb +11 -7
- data/lib/instana/instrumentation/rack.rb +12 -7
- data/lib/instana/instrumentation/shoryuken.rb +44 -0
- 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 +8 -4
- 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/ruby_process.rb +48 -0
- data/lib/instana/tracer.rb +29 -147
- data/lib/instana/tracing/processor.rb +14 -22
- data/lib/instana/tracing/span.rb +34 -37
- data/lib/instana/tracing/span_context.rb +16 -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/aws_test.rb +130 -2
- data/test/instrumentation/excon_test.rb +16 -1
- data/test/instrumentation/net_http_test.rb +18 -0
- data/test/instrumentation/rack_instrumented_request_test.rb +9 -4
- data/test/instrumentation/rack_test.rb +2 -14
- data/test/instrumentation/shoryuken_test.rb +47 -0
- 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 +86 -46
- data/Dockerfile +0 -16
- 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
@@ -5,12 +5,13 @@ module Instana
|
|
5
5
|
module Instrumentation
|
6
6
|
class Excon < ::Excon::Middleware::Base
|
7
7
|
def request_call(datum)
|
8
|
-
return @stack.request_call(datum) unless
|
8
|
+
return @stack.request_call(datum) unless traceable?
|
9
9
|
|
10
10
|
payload = { :http => {} }
|
11
|
-
path = datum[:path].split('?')
|
11
|
+
path, query = datum[:path].split('?', 2)
|
12
12
|
payload[:http][:url] = ::Instana.secrets.remove_from_query("#{datum[:connection].instance_variable_get(:@socket_key)}#{path}")
|
13
13
|
payload[:http][:method] = datum[:method] if datum.key?(:method)
|
14
|
+
payload[:http][:params] = ::Instana.secrets.remove_from_query(query || '')
|
14
15
|
|
15
16
|
if datum[:pipeline] == true
|
16
17
|
# Pass the context along in the datum so we get back on response
|
@@ -23,19 +24,21 @@ module Instana
|
|
23
24
|
end
|
24
25
|
|
25
26
|
# Set request headers; encode IDs as hexadecimal strings
|
26
|
-
datum[:headers]['X-Instana-
|
27
|
-
datum[:headers]['X-Instana-S'] = t_context.span_id_header
|
27
|
+
datum[:headers]['X-Instana-L'] = t_context.level.to_s
|
28
28
|
|
29
|
-
if
|
30
|
-
datum[:headers]['
|
31
|
-
datum[:headers]['
|
29
|
+
if t_context.active?
|
30
|
+
datum[:headers]['X-Instana-T'] = t_context.trace_id_header
|
31
|
+
datum[:headers]['X-Instana-S'] = t_context.span_id_header
|
32
32
|
end
|
33
33
|
|
34
|
+
datum[:headers]['Traceparent'] = t_context.trace_parent_header
|
35
|
+
datum[:headers]['Tracestate'] = t_context.trace_state_header unless t_context.trace_state_header.empty?
|
36
|
+
|
34
37
|
@stack.request_call(datum)
|
35
38
|
end
|
36
39
|
|
37
40
|
def error_call(datum)
|
38
|
-
return @stack.error_call(datum) unless
|
41
|
+
return @stack.error_call(datum) unless traceable?
|
39
42
|
|
40
43
|
if datum[:pipeline] == true
|
41
44
|
::Instana.tracer.log_async_error(datum[:error], datum[:instana_span])
|
@@ -48,7 +51,7 @@ module Instana
|
|
48
51
|
def response_call(datum)
|
49
52
|
# FIXME: Will connect exceptions call a response?
|
50
53
|
#
|
51
|
-
return @stack.response_call(datum) unless
|
54
|
+
return @stack.response_call(datum) unless traceable?
|
52
55
|
|
53
56
|
result = @stack.response_call(datum)
|
54
57
|
|
@@ -71,6 +74,13 @@ module Instana
|
|
71
74
|
end
|
72
75
|
result
|
73
76
|
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def traceable?
|
81
|
+
::Instana.tracer.tracing? &&
|
82
|
+
(!Instana.tracer.current_span.exit_span? || Instana.tracer.current_span.name == :excon)
|
83
|
+
end
|
74
84
|
end
|
75
85
|
end
|
76
86
|
end
|
@@ -18,16 +18,33 @@ module Instana
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def incoming_context
|
21
|
-
context = if
|
21
|
+
context = if !correlation_data.empty?
|
22
|
+
{}
|
23
|
+
elsif @env['HTTP_X_INSTANA_T']
|
22
24
|
context_from_instana_headers
|
23
|
-
elsif @env['HTTP_TRACEPARENT']
|
25
|
+
elsif @env['HTTP_TRACEPARENT']
|
24
26
|
context_from_trace_parent
|
27
|
+
elsif @env['HTTP_TRACESTATE']
|
28
|
+
context_from_trace_state
|
25
29
|
else
|
26
30
|
{}
|
27
31
|
end
|
28
32
|
|
29
33
|
context[:level] = @env['HTTP_X_INSTANA_L'][0] if @env['HTTP_X_INSTANA_L']
|
30
34
|
|
35
|
+
unless ::Instana.config[:w3_trace_correlation]
|
36
|
+
trace_state = parse_trace_state
|
37
|
+
|
38
|
+
if context[:from_w3] && trace_state.empty?
|
39
|
+
context.delete(:span_id)
|
40
|
+
context[:from_w3] = false
|
41
|
+
elsif context[:from_w3] && !trace_state.empty?
|
42
|
+
context[:trace_id] = trace_state[:t]
|
43
|
+
context[:span_id] = trace_state[:p]
|
44
|
+
context[:from_w3] = false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
31
48
|
context
|
32
49
|
end
|
33
50
|
|
@@ -46,12 +63,17 @@ module Instana
|
|
46
63
|
headers
|
47
64
|
end
|
48
65
|
|
66
|
+
def request_params
|
67
|
+
::Instana.secrets.remove_from_query(@env['QUERY_STRING'])
|
68
|
+
end
|
69
|
+
|
49
70
|
def request_tags
|
50
71
|
{
|
51
72
|
method: request_method,
|
52
73
|
url: CGI.unescape(path_info),
|
53
74
|
host: host_with_port,
|
54
|
-
header: extra_header_tags
|
75
|
+
header: extra_header_tags,
|
76
|
+
params: request_params
|
55
77
|
}.compact
|
56
78
|
end
|
57
79
|
|
@@ -64,19 +86,43 @@ module Instana
|
|
64
86
|
end
|
65
87
|
|
66
88
|
def continuing_from_trace_parent?
|
67
|
-
incoming_context
|
89
|
+
incoming_context[:from_w3]
|
68
90
|
end
|
69
91
|
|
70
92
|
def synthetic?
|
71
93
|
@env.has_key?('HTTP_X_INSTANA_SYNTHETIC') && @env['HTTP_X_INSTANA_SYNTHETIC'].eql?('1')
|
72
94
|
end
|
73
95
|
|
96
|
+
def long_instana_id?
|
97
|
+
::Instana::Util.header_to_id(@env['HTTP_X_INSTANA_T']).length == 32
|
98
|
+
end
|
99
|
+
|
100
|
+
def external_trace_id?
|
101
|
+
continuing_from_trace_parent? || long_instana_id?
|
102
|
+
end
|
103
|
+
|
104
|
+
def external_trace_id
|
105
|
+
incoming_context[:long_instana_id] || incoming_context[:external_trace_id]
|
106
|
+
end
|
107
|
+
|
74
108
|
private
|
75
109
|
|
76
110
|
def context_from_instana_headers
|
111
|
+
sanitized_t = ::Instana::Util.header_to_id(@env['HTTP_X_INSTANA_T'])
|
112
|
+
sanitized_s = ::Instana::Util.header_to_id(@env['HTTP_X_INSTANA_S'])
|
113
|
+
external_trace_id = if @env['HTTP_TRACEPARENT']
|
114
|
+
context_from_trace_parent[:external_trace_id]
|
115
|
+
elsif long_instana_id?
|
116
|
+
sanitized_t
|
117
|
+
end
|
118
|
+
|
77
119
|
{
|
78
|
-
|
79
|
-
|
120
|
+
span_id: sanitized_s,
|
121
|
+
trace_id: long_instana_id? ? sanitized_t[16..-1] : sanitized_t, # rubocop:disable Style/SlicingWithRange, Lint/RedundantCopDisableDirective
|
122
|
+
long_instana_id: long_instana_id? ? sanitized_t : nil,
|
123
|
+
external_trace_id: external_trace_id,
|
124
|
+
external_state: @env['HTTP_TRACESTATE'],
|
125
|
+
from_w3: false
|
80
126
|
}.compact
|
81
127
|
end
|
82
128
|
|
@@ -85,14 +131,28 @@ module Instana
|
|
85
131
|
matches = @env['HTTP_TRACEPARENT'].match(W3_TRACE_PARENT_FORMAT)
|
86
132
|
return {} unless matches
|
87
133
|
|
134
|
+
trace_id = ::Instana::Util.header_to_id(matches['trace'][16..-1]) # rubocop:disable Style/SlicingWithRange, Lint/RedundantCopDisableDirective
|
135
|
+
span_id = ::Instana::Util.header_to_id(matches['parent'])
|
136
|
+
|
88
137
|
{
|
89
138
|
external_trace_id: matches['trace'],
|
90
139
|
external_state: @env['HTTP_TRACESTATE'],
|
91
|
-
trace_id:
|
92
|
-
span_id:
|
140
|
+
trace_id: trace_id,
|
141
|
+
span_id: span_id,
|
142
|
+
from_w3: true
|
93
143
|
}
|
94
144
|
end
|
95
145
|
|
146
|
+
def context_from_trace_state
|
147
|
+
state = parse_trace_state
|
148
|
+
|
149
|
+
{
|
150
|
+
trace_id: state[:t],
|
151
|
+
span_id: state[:p],
|
152
|
+
from_w3: false
|
153
|
+
}.compact
|
154
|
+
end
|
155
|
+
|
96
156
|
def parse_trace_state
|
97
157
|
return {} unless @env.has_key?('HTTP_TRACESTATE')
|
98
158
|
token = @env['HTTP_TRACESTATE']
|
@@ -19,20 +19,24 @@ module Instana
|
|
19
19
|
|
20
20
|
# Set request headers; encode IDs as hexadecimal strings
|
21
21
|
t_context = ::Instana.tracer.context
|
22
|
-
request['X-Instana-
|
23
|
-
request['X-Instana-S'] = t_context.span_id_header
|
22
|
+
request['X-Instana-L'] = t_context.level.to_s
|
24
23
|
|
25
|
-
if
|
26
|
-
request['
|
27
|
-
request['
|
24
|
+
if t_context.active?
|
25
|
+
request['X-Instana-T'] = t_context.trace_id_header
|
26
|
+
request['X-Instana-S'] = t_context.span_id_header
|
28
27
|
end
|
29
28
|
|
29
|
+
request['Traceparent'] = t_context.trace_parent_header
|
30
|
+
request['Tracestate'] = t_context.trace_state_header unless t_context.trace_state_header.empty?
|
31
|
+
|
30
32
|
# Collect up KV info now in case any exception is raised
|
31
33
|
kv_payload = { :http => {} }
|
32
34
|
kv_payload[:http][:method] = request.method
|
33
35
|
|
34
36
|
if request.uri
|
35
|
-
|
37
|
+
uri_without_query = request.uri.dup.tap { |r| r.query = nil }
|
38
|
+
kv_payload[:http][:url] = uri_without_query.to_s.gsub(/\?\z/, '')
|
39
|
+
kv_payload[:http][:params] = ::Instana.secrets.remove_from_query(request.uri.query)
|
36
40
|
else
|
37
41
|
if use_ssl?
|
38
42
|
kv_payload[:http][:url] = "https://#{@address}:#{@port}#{request.path}"
|
@@ -41,7 +45,7 @@ module Instana
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
kv_payload[:http][:url] = ::Instana.secrets.remove_from_query(kv_payload[:http][:url])
|
48
|
+
kv_payload[:http][:url] = ::Instana.secrets.remove_from_query(kv_payload[:http][:url]).gsub(/\?\z/, '')
|
45
49
|
|
46
50
|
# The core call
|
47
51
|
response = super(*args, &block)
|
@@ -12,7 +12,6 @@ module Instana
|
|
12
12
|
|
13
13
|
def call(env)
|
14
14
|
req = InstrumentedRequest.new(env)
|
15
|
-
return @app.call(env) if req.skip_trace?
|
16
15
|
kvs = {
|
17
16
|
http: req.request_tags,
|
18
17
|
service: ENV['INSTANA_SERVICE_NAME']
|
@@ -34,12 +33,16 @@ module Instana
|
|
34
33
|
|
35
34
|
if req.continuing_from_trace_parent?
|
36
35
|
current_span[:tp] = true
|
37
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
if req.external_trace_id?
|
39
|
+
current_span[:lt] = req.external_trace_id
|
38
40
|
end
|
39
41
|
|
40
42
|
if req.synthetic?
|
41
43
|
current_span[:sy] = true
|
42
44
|
end
|
45
|
+
|
43
46
|
# In case some previous middleware returned a string status, make sure that we're dealing with
|
44
47
|
# an integer. In Ruby nil.to_i, "asdfasdf".to_i will always return 0 from Ruby versions 1.8.7 and newer.
|
45
48
|
# So if an 0 status is reported here, it indicates some other issue (e.g. no status from previous middleware)
|
@@ -70,15 +73,17 @@ module Instana
|
|
70
73
|
if ::Instana.tracer.tracing?
|
71
74
|
if headers
|
72
75
|
# Set response headers; encode as hex string
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
+
if trace_context.active?
|
77
|
+
headers['X-Instana-T'] = trace_context.trace_id_header
|
78
|
+
headers['X-Instana-S'] = trace_context.span_id_header
|
79
|
+
headers['X-Instana-L'] = '1'
|
76
80
|
|
77
|
-
if ::Instana.config[:w3_trace_correlation]
|
78
|
-
headers['Traceparent'] = trace_context.trace_parent_header
|
79
81
|
headers['Tracestate'] = trace_context.trace_state_header
|
82
|
+
else
|
83
|
+
headers['X-Instana-L'] = '0'
|
80
84
|
end
|
81
85
|
|
86
|
+
headers['Traceparent'] = trace_context.trace_parent_header
|
82
87
|
headers['Server-Timing'] = "intid;desc=#{trace_context.trace_id_header}"
|
83
88
|
end
|
84
89
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
module Instana
|
5
|
+
module Instrumentation
|
6
|
+
class Shoryuken
|
7
|
+
def call(_worker_instance, _queue, sqs_message, _body, &block)
|
8
|
+
if sqs_message.is_a? Array
|
9
|
+
return yield
|
10
|
+
end
|
11
|
+
|
12
|
+
sqs_tags = {
|
13
|
+
sort: 'entry',
|
14
|
+
queue: sqs_message.queue_url
|
15
|
+
}
|
16
|
+
|
17
|
+
context = incomming_context_from(sqs_message.message_attributes)
|
18
|
+
::Instana.tracer.start_or_continue_trace(:sqs, {sqs: sqs_tags}, context, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def incomming_context_from(attributes)
|
24
|
+
trace_id = try(attributes, 'X_INSTANA_T', 'X_INSTANA_ST')
|
25
|
+
span_id = try(attributes, 'X_INSTANA_S', 'X_INSTANA_SS')
|
26
|
+
level = try(attributes, 'X_INSTANA_L', 'X_INSTANA_SL')
|
27
|
+
|
28
|
+
{
|
29
|
+
trace_id: trace_id,
|
30
|
+
span_id: span_id,
|
31
|
+
level: level
|
32
|
+
}.compact
|
33
|
+
end
|
34
|
+
|
35
|
+
def try(attributes, *args)
|
36
|
+
key = args.detect do |a|
|
37
|
+
attributes && attributes[a] && attributes[a].respond_to?(:string_value)
|
38
|
+
end
|
39
|
+
|
40
|
+
attributes[key].string_value if attributes && key
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
module Instana
|
5
|
+
class LoggerDelegator < SimpleDelegator
|
6
|
+
def initialize(obj)
|
7
|
+
obj.level = level_from_environment
|
8
|
+
super(obj)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def level_from_environment
|
14
|
+
# :nocov:
|
15
|
+
return Logger::FATAL if ENV.key?('INSTANA_TEST') || ENV.key?('RACK_TEST')
|
16
|
+
return Logger::DEBUG if ENV.key?('INSTANA_DEBUG')
|
17
|
+
|
18
|
+
case ENV['INSTANA_LOG_LEVEL']
|
19
|
+
when 'debug'
|
20
|
+
Logger::DEBUG
|
21
|
+
when 'warn'
|
22
|
+
Logger::WARN
|
23
|
+
when 'error'
|
24
|
+
Logger::ERROR
|
25
|
+
else
|
26
|
+
Logger::INFO
|
27
|
+
end
|
28
|
+
# :nocov:
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
File without changes
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'delegate'
|
5
|
+
# :nocov:
|
6
|
+
module OpenTracing
|
7
|
+
class InstanaTracer < SimpleDelegator
|
8
|
+
Span = ::Instana::Span
|
9
|
+
|
10
|
+
# Start a new span
|
11
|
+
#
|
12
|
+
# @param operation_name [String] The name of the operation represented by the span
|
13
|
+
# @param child_of [Span] A span to be used as the ChildOf reference
|
14
|
+
# @param start_time [Time] the start time of the span
|
15
|
+
# @param tags [Hash] Starting tags for the span
|
16
|
+
#
|
17
|
+
# @return [Span]
|
18
|
+
#
|
19
|
+
def start_span(operation_name, child_of: nil, start_time: ::Instana::Util.now_in_ms, tags: nil)
|
20
|
+
new_span = if child_of && (child_of.is_a?(::Instana::Span) || child_of.is_a?(::Instana::SpanContext))
|
21
|
+
Span.new(operation_name, parent_ctx: child_of, start_time: start_time)
|
22
|
+
else
|
23
|
+
Span.new(operation_name, start_time: start_time)
|
24
|
+
end
|
25
|
+
new_span.set_tags(tags) if tags
|
26
|
+
new_span
|
27
|
+
end
|
28
|
+
|
29
|
+
# Start a new span which is the child of the current span
|
30
|
+
#
|
31
|
+
# @param operation_name [String] The name of the operation represented by the span
|
32
|
+
# @param child_of [Span] A span to be used as the ChildOf reference
|
33
|
+
# @param start_time [Time] the start time of the span
|
34
|
+
# @param tags [Hash] Starting tags for the span
|
35
|
+
#
|
36
|
+
# @return [Span]
|
37
|
+
#
|
38
|
+
def start_active_span(operation_name, child_of: active_span, start_time: ::Instana::Util.now_in_ms, tags: nil)
|
39
|
+
::Instana.tracer.current_span = start_span(operation_name, child_of: child_of, start_time: start_time, tags: tags)
|
40
|
+
block_given? ? yield(::Instana.tracer.current_span) : ::Instana.tracer.current_span
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the currently active span
|
44
|
+
#
|
45
|
+
# @return [Span]
|
46
|
+
#
|
47
|
+
def active_span
|
48
|
+
::Instana.tracer.current_span
|
49
|
+
end
|
50
|
+
|
51
|
+
# Inject a span into the given carrier
|
52
|
+
#
|
53
|
+
# @param span_context [SpanContext]
|
54
|
+
# @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK]
|
55
|
+
# @param carrier [Carrier]
|
56
|
+
#
|
57
|
+
def inject(span_context, format, carrier)
|
58
|
+
case format
|
59
|
+
when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY
|
60
|
+
::Instana.logger.debug 'Unsupported inject format'
|
61
|
+
when OpenTracing::FORMAT_RACK
|
62
|
+
carrier['X-Instana-T'] = ::Instana::Util.id_to_header(span_context.trace_id)
|
63
|
+
carrier['X-Instana-S'] = ::Instana::Util.id_to_header(span_context.span_id)
|
64
|
+
else
|
65
|
+
::Instana.logger.debug 'Unknown inject format'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Extract a span from a carrier
|
70
|
+
#
|
71
|
+
# @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK]
|
72
|
+
# @param carrier [Carrier]
|
73
|
+
#
|
74
|
+
# @return [SpanContext]
|
75
|
+
#
|
76
|
+
def extract(format, carrier)
|
77
|
+
case format
|
78
|
+
when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY
|
79
|
+
::Instana.logger.debug 'Unsupported extract format'
|
80
|
+
when OpenTracing::FORMAT_RACK
|
81
|
+
::Instana::SpanContext.new(::Instana::Util.header_to_id(carrier['HTTP_X_INSTANA_T']),
|
82
|
+
::Instana::Util.header_to_id(carrier['HTTP_X_INSTANA_S']))
|
83
|
+
else
|
84
|
+
::Instana.logger.debug 'Unknown inject format'
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def method_missing(method, *args, &block)
|
90
|
+
::Instana.logger.warn { "You are invoking `#{m}` on Instana::Tracer via OpenTracing." }
|
91
|
+
super(method, *args, &block)
|
92
|
+
end
|
93
|
+
|
94
|
+
def respond_to_missing?(*)
|
95
|
+
super(method)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
# :nocov:
|