instana 1.9.7 → 1.10.0.slimfast
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/instana/agent.rb +19 -19
- data/lib/instana/agent/helpers.rb +2 -2
- data/lib/instana/agent/tasks.rb +2 -2
- data/lib/instana/collectors/gc.rb +1 -1
- data/lib/instana/collectors/memory.rb +1 -1
- data/lib/instana/collectors/thread.rb +1 -1
- data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +1 -1
- data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +1 -1
- data/lib/instana/helpers.rb +2 -2
- data/lib/instana/instrumentation.rb +1 -1
- data/lib/instana/instrumentation/excon.rb +8 -5
- data/lib/instana/instrumentation/rack.rb +2 -2
- data/lib/instana/instrumentation/resque.rb +3 -3
- data/lib/instana/tracer.rb +92 -117
- data/lib/instana/tracing/processor.rb +18 -133
- data/lib/instana/tracing/span.rb +40 -35
- data/lib/instana/tracing/span_context.rb +3 -1
- data/lib/instana/util.rb +5 -5
- data/lib/instana/version.rb +1 -1
- data/lib/opentracing.rb +1 -1
- data/test/frameworks/rack_test.rb +6 -11
- data/test/frameworks/rails/actioncontroller_test.rb +32 -62
- data/test/frameworks/rails/actionview5_test.rb +91 -132
- data/test/frameworks/rails/activerecord5_test.rb +14 -17
- data/test/instrumentation/dalli_test.rb +51 -72
- data/test/instrumentation/excon_test.rb +70 -94
- data/test/instrumentation/grpc_test.rb +164 -126
- data/test/instrumentation/net-http_test.rb +48 -57
- data/test/instrumentation/redis_test.rb +4 -6
- data/test/instrumentation/resque_test.rb +41 -41
- data/test/instrumentation/rest-client_test.rb +25 -31
- data/test/instrumentation/sidekiq-client_test.rb +12 -20
- data/test/instrumentation/sidekiq-worker_test.rb +48 -63
- data/test/jobs/resque_error_job.rb +7 -1
- data/test/jobs/resque_fast_job.rb +7 -1
- data/test/servers/sidekiq/worker.rb +1 -3
- data/test/test_helper.rb +58 -0
- data/test/tracing/custom_test.rb +11 -19
- data/test/tracing/opentracing_test.rb +48 -156
- data/test/tracing/trace_test.rb +67 -67
- data/test/tracing/tracer_async_test.rb +75 -175
- data/test/tracing/tracer_test.rb +75 -75
- metadata +4 -5
- data/lib/instana/tracing/trace.rb +0 -316
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 636d84b9e35dfd6f03f1186ecda22b22b96105725007ca2f48dccc41198782f7
|
4
|
+
data.tar.gz: 16842c4bacc3cac2c347babee2653fbfd3462fb0ee466b5317d22167465088ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e30db43f11f5b3574405ef02ce18c1bb755bad5b0b5e28bd3f8d5a74846b9feeb08e0541f66a74bb174cb4c01be889ab896a34b988d26ab93577f4de2561c34a
|
7
|
+
data.tar.gz: 2cc0b8257cdb95df46fa3955c081a12188d7abf4f0a639929f50264b94961fa61bb9de4f092cf04d0144c985d4a871084114aaad14ad1b7671dea908b4a3bd43
|
data/lib/instana/agent.rb
CHANGED
@@ -167,8 +167,8 @@ module Instana
|
|
167
167
|
@timers.wait
|
168
168
|
end
|
169
169
|
rescue Exception => e
|
170
|
-
::Instana.logger.warn "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
171
|
-
::Instana.logger.debug e.backtrace.join("\r\n")
|
170
|
+
::Instana.logger.warn { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
171
|
+
::Instana.logger.debug { e.backtrace.join("\r\n") }
|
172
172
|
ensure
|
173
173
|
if @state == :announced
|
174
174
|
# Pause the timers so they don't fire while we are
|
@@ -176,7 +176,7 @@ module Instana
|
|
176
176
|
@collect_timer.pause
|
177
177
|
@announce_timer.pause
|
178
178
|
|
179
|
-
::Instana.logger.debug "#{Thread.current}: Agent exiting. Reporting final #{::Instana.processor.queue_count} trace(s)."
|
179
|
+
::Instana.logger.debug { "#{Thread.current}: Agent exiting. Reporting final #{::Instana.processor.queue_count} trace(s)." }
|
180
180
|
::Instana.processor.send
|
181
181
|
end
|
182
182
|
end
|
@@ -211,7 +211,7 @@ module Instana
|
|
211
211
|
req = Net::HTTP::Put.new(uri)
|
212
212
|
req.body = Oj.dump(announce_payload, OJ_OPTIONS)
|
213
213
|
|
214
|
-
::Instana.logger.debug "Announce: http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH} - payload: #{req.body}"
|
214
|
+
::Instana.logger.debug { "Announce: http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH} - payload: #{req.body}" }
|
215
215
|
|
216
216
|
response = make_host_agent_request(req)
|
217
217
|
|
@@ -228,8 +228,8 @@ module Instana
|
|
228
228
|
false
|
229
229
|
end
|
230
230
|
rescue => e
|
231
|
-
Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
232
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
231
|
+
Instana.logger.info { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
232
|
+
Instana.logger.debug { e.backtrace.join("\r\n") }
|
233
233
|
return false
|
234
234
|
ensure
|
235
235
|
socket.close if socket
|
@@ -269,8 +269,8 @@ module Instana
|
|
269
269
|
end
|
270
270
|
false
|
271
271
|
rescue => e
|
272
|
-
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
273
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
272
|
+
Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
273
|
+
Instana.logger.debug { e.backtrace.join("\r\n") }
|
274
274
|
end
|
275
275
|
|
276
276
|
# Accept and report spans to the host agent.
|
@@ -304,8 +304,8 @@ module Instana
|
|
304
304
|
end
|
305
305
|
false
|
306
306
|
rescue => e
|
307
|
-
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
308
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
307
|
+
Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
308
|
+
Instana.logger.debug { e.backtrace.join("\r\n") }
|
309
309
|
end
|
310
310
|
|
311
311
|
# Check that the host agent is available and can be contacted. This will
|
@@ -328,8 +328,8 @@ module Instana
|
|
328
328
|
end
|
329
329
|
false
|
330
330
|
rescue => e
|
331
|
-
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
332
|
-
Instana.logger.debug e.backtrace.join("\r\n") unless ENV.key?('INSTANA_TEST')
|
331
|
+
Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
332
|
+
Instana.logger.debug { e.backtrace.join("\r\n") } unless ENV.key?('INSTANA_TEST')
|
333
333
|
return false
|
334
334
|
end
|
335
335
|
|
@@ -342,20 +342,20 @@ module Instana
|
|
342
342
|
def run_discovery
|
343
343
|
discovered = {}
|
344
344
|
|
345
|
-
::Instana.logger.debug "#{__method__}: Running agent discovery..."
|
345
|
+
::Instana.logger.debug { "#{__method__}: Running agent discovery..." }
|
346
346
|
|
347
347
|
# Try default location or manually configured (if so)
|
348
348
|
uri = URI.parse("http://#{::Instana.config[:agent_host]}:#{::Instana.config[:agent_port]}/")
|
349
349
|
req = Net::HTTP::Get.new(uri)
|
350
350
|
|
351
|
-
::Instana.logger.debug "#{__method__}: Trying #{::Instana.config[:agent_host]}:#{::Instana.config[:agent_port]}"
|
351
|
+
::Instana.logger.debug { "#{__method__}: Trying #{::Instana.config[:agent_host]}:#{::Instana.config[:agent_port]}" }
|
352
352
|
|
353
353
|
response = make_host_agent_request(req)
|
354
354
|
|
355
355
|
if response && (response.code.to_i == 200)
|
356
356
|
discovered[:agent_host] = ::Instana.config[:agent_host]
|
357
357
|
discovered[:agent_port] = ::Instana.config[:agent_port]
|
358
|
-
::Instana.logger.debug "#{__method__}: Found #{discovered[:agent_host]}:#{discovered[:agent_port]}"
|
358
|
+
::Instana.logger.debug { "#{__method__}: Found #{discovered[:agent_host]}:#{discovered[:agent_port]}" }
|
359
359
|
return discovered
|
360
360
|
end
|
361
361
|
|
@@ -366,14 +366,14 @@ module Instana
|
|
366
366
|
uri = URI.parse("http://#{@default_gateway}:#{::Instana.config[:agent_port]}/")
|
367
367
|
req = Net::HTTP::Get.new(uri)
|
368
368
|
|
369
|
-
::Instana.logger.debug "#{__method__}: Trying default gateway #{@default_gateway}:#{::Instana.config[:agent_port]}"
|
369
|
+
::Instana.logger.debug { "#{__method__}: Trying default gateway #{@default_gateway}:#{::Instana.config[:agent_port]}" }
|
370
370
|
|
371
371
|
response = make_host_agent_request(req)
|
372
372
|
|
373
373
|
if response && (response.code.to_i == 200)
|
374
374
|
discovered[:agent_host] = @default_gateway
|
375
375
|
discovered[:agent_port] = ::Instana.config[:agent_port]
|
376
|
-
::Instana.logger.debug "#{__method__}: Found #{discovered[:agent_host]}:#{discovered[:agent_port]}"
|
376
|
+
::Instana.logger.debug { "#{__method__}: Found #{discovered[:agent_host]}:#{discovered[:agent_port]}" }
|
377
377
|
return discovered
|
378
378
|
end
|
379
379
|
|
@@ -434,8 +434,8 @@ module Instana
|
|
434
434
|
rescue Errno::ECONNREFUSED
|
435
435
|
return nil
|
436
436
|
rescue => e
|
437
|
-
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
438
|
-
Instana.logger.debug e.backtrace.join("\r\n") unless ENV.key?('INSTANA_TEST')
|
437
|
+
Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
438
|
+
Instana.logger.debug { e.backtrace.join("\r\n") } unless ENV.key?('INSTANA_TEST')
|
439
439
|
return nil
|
440
440
|
end
|
441
441
|
end
|
@@ -51,8 +51,8 @@ module AgentHelpers
|
|
51
51
|
|
52
52
|
@state == :announced
|
53
53
|
rescue => e
|
54
|
-
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
55
|
-
Instana.logger.debug e.backtrace.join("\r\n") unless ENV.key?('INSTANA_TEST')
|
54
|
+
Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
55
|
+
Instana.logger.debug { e.backtrace.join("\r\n") } unless ENV.key?('INSTANA_TEST')
|
56
56
|
return false
|
57
57
|
end
|
58
58
|
end
|
data/lib/instana/agent/tasks.rb
CHANGED
@@ -42,7 +42,7 @@ module AgentTasks
|
|
42
42
|
make_host_agent_request(req)
|
43
43
|
|
44
44
|
rescue StandardError => e
|
45
|
-
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
46
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
45
|
+
Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
46
|
+
Instana.logger.debug { e.backtrace.join("\r\n") }
|
47
47
|
end
|
48
48
|
end
|
@@ -45,7 +45,7 @@ module Instana
|
|
45
45
|
@this_gc
|
46
46
|
rescue => e
|
47
47
|
::Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
48
|
-
::Instana.logger.debug e.backtrace.join("\r\n")
|
48
|
+
::Instana.logger.debug { e.backtrace.join("\r\n") }
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -22,7 +22,7 @@ module Instana
|
|
22
22
|
@this_mem
|
23
23
|
rescue => e
|
24
24
|
::Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
25
|
-
::Instana.logger.debug e.backtrace.join("\r\n")
|
25
|
+
::Instana.logger.debug { e.backtrace.join("\r\n") }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -18,7 +18,7 @@ module Instana
|
|
18
18
|
@this_count
|
19
19
|
rescue => e
|
20
20
|
::Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
21
|
-
::Instana.logger.debug e.backtrace.join("\r\n")
|
21
|
+
::Instana.logger.debug { e.backtrace.join("\r\n") }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -67,7 +67,7 @@ module Instana
|
|
67
67
|
|
68
68
|
def exec_query_with_instana(sql, name = 'SQL', binds = [], *args)
|
69
69
|
if !::Instana.tracer.tracing? || ignore_payload?(name, sql) ||
|
70
|
-
::Instana.tracer.
|
70
|
+
::Instana.tracer.current_span[:n] == :activerecord
|
71
71
|
return exec_query_without_instana(sql, name, binds, *args)
|
72
72
|
end
|
73
73
|
|
@@ -42,7 +42,7 @@ module Instana
|
|
42
42
|
|
43
43
|
def exec_query_with_instana(sql, name = 'SQL', binds = [], *args)
|
44
44
|
if !::Instana.tracer.tracing? || ignore_payload?(name, sql) ||
|
45
|
-
::Instana.tracer.
|
45
|
+
::Instana.tracer.current_span[:n] == :activerecord
|
46
46
|
return exec_query_without_instana(sql, name, binds, *args)
|
47
47
|
end
|
48
48
|
|
data/lib/instana/helpers.rb
CHANGED
@@ -16,7 +16,7 @@ module Instana
|
|
16
16
|
ERB.new(EUM_SNIPPET).result
|
17
17
|
rescue => e
|
18
18
|
Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
19
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
19
|
+
Instana.logger.debug { e.backtrace.join("\r\n") }
|
20
20
|
return nil
|
21
21
|
end
|
22
22
|
|
@@ -32,7 +32,7 @@ module Instana
|
|
32
32
|
ERB.new(EUM_TEST_SNIPPET).result
|
33
33
|
rescue => e
|
34
34
|
Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
35
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
35
|
+
Instana.logger.debug { e.backtrace.join("\r\n") }
|
36
36
|
return nil
|
37
37
|
end
|
38
38
|
end
|
@@ -14,7 +14,7 @@ if !ENV.key?('INSTANA_DISABLE_AUTO_INSTR') || ENV['INSTANA_DISABLE_AUTO_INSTR']
|
|
14
14
|
require f
|
15
15
|
rescue => e
|
16
16
|
Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
17
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
17
|
+
Instana.logger.debug { e.backtrace.join("\r\n") }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -13,13 +13,14 @@ if defined?(::Excon) && ::Instana.config[:excon][:enabled]
|
|
13
13
|
if datum[:pipeline] == true
|
14
14
|
# Pass the context along in the datum so we get back on response
|
15
15
|
# and can close out the async span
|
16
|
-
datum[:
|
16
|
+
datum[:instana_span] = ::Instana.tracer.log_async_entry(:excon, payload)
|
17
|
+
t_context = datum[:instana_span].context
|
17
18
|
else
|
18
19
|
::Instana.tracer.log_entry(:excon, payload)
|
20
|
+
t_context = ::Instana.tracer.context
|
19
21
|
end
|
20
22
|
|
21
23
|
# Set request headers; encode IDs as hexadecimal strings
|
22
|
-
t_context = ::Instana.tracer.context
|
23
24
|
datum[:headers]['X-Instana-T'] = t_context.trace_id_header
|
24
25
|
datum[:headers]['X-Instana-S'] = t_context.span_id_header
|
25
26
|
|
@@ -30,7 +31,7 @@ if defined?(::Excon) && ::Instana.config[:excon][:enabled]
|
|
30
31
|
return @stack.error_call(datum) unless ::Instana.tracer.tracing?
|
31
32
|
|
32
33
|
if datum[:pipeline] == true
|
33
|
-
::Instana.tracer.log_async_error(datum[:error], datum[:
|
34
|
+
::Instana.tracer.log_async_error(datum[:error], datum[:instana_span])
|
34
35
|
else
|
35
36
|
::Instana.tracer.log_error(datum[:error])
|
36
37
|
end
|
@@ -38,6 +39,8 @@ if defined?(::Excon) && ::Instana.config[:excon][:enabled]
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def response_call(datum)
|
42
|
+
# FIXME: Will connect exceptions call a response?
|
43
|
+
#
|
41
44
|
return @stack.response_call(datum) unless ::Instana.tracer.tracing?
|
42
45
|
|
43
46
|
result = @stack.response_call(datum)
|
@@ -54,8 +57,8 @@ if defined?(::Excon) && ::Instana.config[:excon][:enabled]
|
|
54
57
|
end
|
55
58
|
|
56
59
|
if datum[:pipeline] == true
|
57
|
-
# Pickup context of this async span from datum[:
|
58
|
-
::Instana.tracer.log_async_exit(:excon, { :http => {:status => status } }, datum[:
|
60
|
+
# Pickup context of this async span from datum[:instana_span]
|
61
|
+
::Instana.tracer.log_async_exit(:excon, { :http => {:status => status } }, datum[:instana_span])
|
59
62
|
else
|
60
63
|
::Instana.tracer.log_exit(:excon, { :http => {:status => status } })
|
61
64
|
end
|
@@ -57,8 +57,8 @@ module Instana
|
|
57
57
|
|
58
58
|
# Save the IDs before the trace ends so we can place
|
59
59
|
# them in the response headers in the ensure block
|
60
|
-
trace_id = ::Instana.tracer.trace_id
|
61
|
-
span_id = ::Instana.tracer.
|
60
|
+
trace_id = ::Instana.tracer.current_span.trace_id
|
61
|
+
span_id = ::Instana.tracer.current_span.id
|
62
62
|
end
|
63
63
|
|
64
64
|
[status, headers, response]
|
@@ -17,7 +17,7 @@ module Instana
|
|
17
17
|
kvs[:job] = klass.to_s
|
18
18
|
kvs[:queue] = klass.instance_variable_get(:@queue)
|
19
19
|
rescue => e
|
20
|
-
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
20
|
+
Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
|
21
21
|
end
|
22
22
|
|
23
23
|
{ :'resque-client' => kvs }
|
@@ -77,7 +77,7 @@ module Instana
|
|
77
77
|
kvs[:'resque-worker'][:job] = job.payload['class'].to_s
|
78
78
|
kvs[:'resque-worker'][:queue] = job.queue
|
79
79
|
rescue => e
|
80
|
-
::Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if Instana::Config[:verbose]
|
80
|
+
::Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" } if Instana::Config[:verbose]
|
81
81
|
end
|
82
82
|
|
83
83
|
Instana.tracer.start_or_continue_trace(:'resque-worker', kvs) do
|
@@ -97,7 +97,7 @@ module Instana
|
|
97
97
|
::Instana.tracer.log_error(exception)
|
98
98
|
end
|
99
99
|
rescue Exception => e
|
100
|
-
::Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if Instana::Config[:verbose]
|
100
|
+
::Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" } if Instana::Config[:verbose]
|
101
101
|
ensure
|
102
102
|
fail_without_instana(exception)
|
103
103
|
end
|
data/lib/instana/tracer.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "instana/thread_local"
|
2
|
-
require "instana/tracing/trace"
|
3
2
|
require "instana/tracing/span"
|
4
3
|
require "instana/tracing/span_context"
|
5
4
|
|
@@ -7,7 +6,7 @@ module Instana
|
|
7
6
|
class Tracer
|
8
7
|
extend ::Instana::ThreadLocal
|
9
8
|
|
10
|
-
thread_local :
|
9
|
+
thread_local :current_span
|
11
10
|
|
12
11
|
# Support ::Instana::Tracer.xxx call style for the instantiated tracer
|
13
12
|
class << self
|
@@ -35,7 +34,7 @@ module Instana
|
|
35
34
|
# :span_id the ID of the parent span (must be an unsigned hex-string)
|
36
35
|
# :level specifies data collection level (optional)
|
37
36
|
#
|
38
|
-
def start_or_continue_trace(name, kvs = {}, incoming_context =
|
37
|
+
def start_or_continue_trace(name, kvs = {}, incoming_context = nil, &block)
|
39
38
|
log_start_or_continue(name, kvs, incoming_context)
|
40
39
|
yield
|
41
40
|
rescue Exception => e
|
@@ -75,16 +74,34 @@ module Instana
|
|
75
74
|
#
|
76
75
|
# @param name [String] the name of the span to start
|
77
76
|
# @param kvs [Hash] list of key values to be reported in the span
|
78
|
-
# @param incoming_context [Hash] specifies the incoming context. At a
|
77
|
+
# @param incoming_context [SpanContext or Hash] specifies the incoming context. At a
|
79
78
|
# minimum, it should specify :trace_id and :span_id from the following:
|
80
79
|
# :trace_id the trace ID (must be an unsigned hex-string)
|
81
80
|
# :span_id the ID of the parent span (must be an unsigned hex-string)
|
82
81
|
# :level specifies data collection level (optional)
|
83
82
|
#
|
84
|
-
def log_start_or_continue(name, kvs = {}, incoming_context =
|
83
|
+
def log_start_or_continue(name, kvs = {}, incoming_context = nil)
|
85
84
|
return if !::Instana.agent.ready? || !::Instana.config[:tracing][:enabled]
|
86
85
|
::Instana.logger.debug "#{__method__} passed a block. Use `start_or_continue` instead!" if block_given?
|
87
|
-
|
86
|
+
|
87
|
+
# Handle the potential variations on `incoming_context`
|
88
|
+
if incoming_context
|
89
|
+
if incoming_context.is_a?(Hash)
|
90
|
+
if !incoming_context.empty?
|
91
|
+
parent_context = SpanContext.new(incoming_context[:trace_id], incoming_context[:span_id])
|
92
|
+
end
|
93
|
+
else
|
94
|
+
parent_context = incoming_context
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
if parent_context
|
99
|
+
self.current_span = Span.new(name, parent_ctx: parent_context)
|
100
|
+
else
|
101
|
+
self.current_span = Span.new(name)
|
102
|
+
end
|
103
|
+
self.current_span.set_tags(kvs) unless kvs.empty?
|
104
|
+
self.current_span
|
88
105
|
end
|
89
106
|
|
90
107
|
# Will establish a new span as a child of the current span
|
@@ -93,9 +110,16 @@ module Instana
|
|
93
110
|
# @param name [String] the name of the span to create
|
94
111
|
# @param kvs [Hash] list of key values to be reported in the span
|
95
112
|
#
|
96
|
-
def log_entry(name, kvs =
|
97
|
-
return unless
|
98
|
-
|
113
|
+
def log_entry(name, kvs = nil, start_time = ::Instana::Util.now_in_ms, child_of = nil)
|
114
|
+
return unless self.current_span || child_of
|
115
|
+
|
116
|
+
if child_of && (child_of.is_a?(::Instana::Span) || child_of.is_a?(::Instana::SpanContext))
|
117
|
+
new_span = Span.new(name, parent_ctx: child_of, start_time: start_time)
|
118
|
+
else
|
119
|
+
new_span = Span.new(name, parent_ctx: self.current_span, start_time: start_time)
|
120
|
+
end
|
121
|
+
new_span.set_tags(kvs) if kvs
|
122
|
+
self.current_span = new_span
|
99
123
|
end
|
100
124
|
|
101
125
|
# Add info to the current span
|
@@ -103,8 +127,8 @@ module Instana
|
|
103
127
|
# @param kvs [Hash] list of key values to be reported in the span
|
104
128
|
#
|
105
129
|
def log_info(kvs)
|
106
|
-
return unless
|
107
|
-
self.
|
130
|
+
return unless self.current_span
|
131
|
+
self.current_span.set_tags(kvs)
|
108
132
|
end
|
109
133
|
|
110
134
|
# Add an error to the current span
|
@@ -112,8 +136,8 @@ module Instana
|
|
112
136
|
# @param e [Exception] Add exception to the current span
|
113
137
|
#
|
114
138
|
def log_error(e)
|
115
|
-
return unless
|
116
|
-
self.
|
139
|
+
return unless self.current_span
|
140
|
+
self.current_span.add_error(e)
|
117
141
|
end
|
118
142
|
|
119
143
|
# Closes out the current span
|
@@ -125,15 +149,22 @@ module Instana
|
|
125
149
|
# @param kvs [Hash] list of key values to be reported in the span
|
126
150
|
#
|
127
151
|
def log_exit(name, kvs = {})
|
128
|
-
return unless
|
152
|
+
return unless self.current_span
|
129
153
|
|
130
154
|
if ENV.key?('INSTANA_DEBUG') || ENV.key?('INSTANA_TEST')
|
131
|
-
unless
|
132
|
-
::Instana.logger.debug "Span mismatch: Attempt to exit #{name} span but #{current_span.name} is active."
|
155
|
+
unless self.current_span.name == name
|
156
|
+
::Instana.logger.debug "Span mismatch: Attempt to exit #{name} span but #{self.current_span.name} is active."
|
133
157
|
end
|
134
158
|
end
|
135
159
|
|
136
|
-
self.
|
160
|
+
self.current_span.set_tags(kvs)
|
161
|
+
self.current_span.close
|
162
|
+
|
163
|
+
if self.current_span.parent
|
164
|
+
self.current_span = self.current_span.parent
|
165
|
+
else
|
166
|
+
self.current_span = nil
|
167
|
+
end
|
137
168
|
end
|
138
169
|
|
139
170
|
# Closes out the current span in the current trace
|
@@ -146,28 +177,17 @@ module Instana
|
|
146
177
|
# @param kvs [Hash] list of key values to be reported in the span
|
147
178
|
#
|
148
179
|
def log_end(name, kvs = {}, end_time = ::Instana::Util.now_in_ms)
|
149
|
-
return unless
|
180
|
+
return unless self.current_span
|
150
181
|
|
151
182
|
if ENV.key?('INSTANA_DEBUG') || ENV.key?('INSTANA_TEST')
|
152
|
-
unless
|
153
|
-
::Instana.logger.debug "Span mismatch: Attempt to end #{name} span but #{current_span.name} is active."
|
183
|
+
unless self.current_span.name == name
|
184
|
+
::Instana.logger.debug "Span mismatch: Attempt to end #{name} span but #{self.current_span.name} is active."
|
154
185
|
end
|
155
186
|
end
|
156
187
|
|
157
|
-
self.
|
158
|
-
|
159
|
-
|
160
|
-
if !self.current_trace.has_async? ||
|
161
|
-
(self.current_trace.has_async? && self.current_trace.complete?)
|
162
|
-
Instana.processor.add(self.current_trace)
|
163
|
-
else
|
164
|
-
# This trace still has outstanding/uncompleted asynchronous spans.
|
165
|
-
# Put it in the staging queue until the async span closes out or
|
166
|
-
# 5 minutes has passed. Whichever comes first.
|
167
|
-
Instana.processor.stage(self.current_trace)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
self.current_trace = nil
|
188
|
+
self.current_span.set_tags(kvs)
|
189
|
+
self.current_span.close(end_time)
|
190
|
+
self.current_span = nil
|
171
191
|
end
|
172
192
|
|
173
193
|
###########################################################################
|
@@ -184,80 +204,40 @@ module Instana
|
|
184
204
|
# :span_id => 12345
|
185
205
|
#
|
186
206
|
def log_async_entry(name, kvs)
|
187
|
-
return unless
|
188
|
-
|
207
|
+
return unless self.current_span
|
208
|
+
|
209
|
+
new_span = Span.new(name, parent_ctx: self.current_span)
|
210
|
+
new_span.set_tags(kvs) unless kvs.empty?
|
211
|
+
new_span
|
189
212
|
end
|
190
213
|
|
191
214
|
# Add info to an asynchronous span
|
192
215
|
#
|
193
216
|
# @param kvs [Hash] list of key values to be reported in the span
|
194
|
-
# @param span [Span] the span for this Async op (previously returned
|
195
|
-
# from `log_async_entry`)
|
217
|
+
# @param span [Span] the span for this Async op (previously returned from `log_async_entry`)
|
196
218
|
#
|
197
219
|
def log_async_info(kvs, span)
|
198
|
-
|
199
|
-
# trace. With the trace ID, we check the current trace
|
200
|
-
# but otherwise, we search staged traces.
|
201
|
-
|
202
|
-
if tracing? && self.current_trace.id == span.context.trace_id
|
203
|
-
self.current_trace.add_async_info(kvs, span)
|
204
|
-
else
|
205
|
-
trace = ::Instana.processor.staged_trace(span.context.trace_id)
|
206
|
-
if trace
|
207
|
-
trace.add_async_info(kvs, span)
|
208
|
-
else
|
209
|
-
::Instana.logger.debug "#{__method__}: Couldn't find staged trace. #{span.inspect}"
|
210
|
-
end
|
211
|
-
end
|
220
|
+
span.set_tags(kvs)
|
212
221
|
end
|
213
222
|
|
214
223
|
# Add an error to an asynchronous span
|
215
224
|
#
|
216
225
|
# @param e [Exception] Add exception to the current span
|
217
|
-
# @param span [Span] the span for this Async op (previously returned
|
218
|
-
# from `log_async_entry`)
|
226
|
+
# @param span [Span] the span for this Async op (previously returned from `log_async_entry`)
|
219
227
|
#
|
220
228
|
def log_async_error(e, span)
|
221
|
-
|
222
|
-
# trace. With the trace ID, we check the current trace
|
223
|
-
# but otherwise, we search staged traces.
|
224
|
-
|
225
|
-
if tracing? && self.current_trace.id == span.context.trace_id
|
226
|
-
self.current_trace.add_async_error(e, span)
|
227
|
-
else
|
228
|
-
trace = ::Instana.processor.staged_trace(span.context.trace_id)
|
229
|
-
if trace
|
230
|
-
trace.add_async_error(e, span)
|
231
|
-
else
|
232
|
-
::Instana.logger.debug "#{__method__}: Couldn't find staged trace. #{span.inspect}"
|
233
|
-
end
|
234
|
-
end
|
229
|
+
span.add_error(e)
|
235
230
|
end
|
236
231
|
|
237
232
|
# Closes out an asynchronous span
|
238
233
|
#
|
239
234
|
# @param name [String] the name of the async span to exit (close out)
|
240
|
-
# @param kvs [Hash] list of key
|
241
|
-
# @param span [Span] the span for this Async op (previously returned
|
242
|
-
# from `log_async_entry`)
|
235
|
+
# @param kvs [Hash] list of additional key/values to be reported in the span (or use {})
|
236
|
+
# @param span [Span] the span for this Async op (previously returned from `log_async_entry`)
|
243
237
|
#
|
244
238
|
def log_async_exit(_name, kvs, span)
|
245
|
-
|
246
|
-
|
247
|
-
# on the right trace.
|
248
|
-
|
249
|
-
if tracing? && self.current_trace.id == span.context.trace_id
|
250
|
-
self.current_trace.end_async_span(kvs, span)
|
251
|
-
else
|
252
|
-
# Different trace from current so find the staged trace
|
253
|
-
# and close out the span on it.
|
254
|
-
trace = ::Instana.processor.staged_trace(span.context.trace_id)
|
255
|
-
if trace
|
256
|
-
trace.end_async_span(kvs, span)
|
257
|
-
else
|
258
|
-
::Instana.logger.debug "#{__method__}: Couldn't find staged trace. #{span.inspect}"
|
259
|
-
end
|
260
|
-
end
|
239
|
+
span.set_tags(kvs) unless kvs.empty?
|
240
|
+
span.close
|
261
241
|
end
|
262
242
|
|
263
243
|
###########################################################################
|
@@ -274,16 +254,13 @@ module Instana
|
|
274
254
|
# @return [Span]
|
275
255
|
#
|
276
256
|
def start_span(operation_name, child_of: nil, start_time: ::Instana::Util.now_in_ms, tags: nil)
|
277
|
-
|
278
|
-
|
279
|
-
if tracing?
|
280
|
-
span = self.current_trace.new_span(operation_name, tags, start_time, child_of)
|
257
|
+
if child_of && (child_of.is_a?(::Instana::Span) || child_of.is_a?(::Instana::SpanContext))
|
258
|
+
new_span = Span.new(operation_name, parent_ctx: child_of, start_time: start_time)
|
281
259
|
else
|
282
|
-
|
283
|
-
span = self.current_trace.current_span
|
260
|
+
new_span = Span.new(operation_name, start_time: start_time)
|
284
261
|
end
|
285
|
-
|
286
|
-
|
262
|
+
new_span.set_tags(tags) if tags
|
263
|
+
new_span
|
287
264
|
end
|
288
265
|
|
289
266
|
# Inject a span into the given carrier
|
@@ -338,7 +315,7 @@ module Instana
|
|
338
315
|
# The non-nil value of this instance variable
|
339
316
|
# indicates if we are currently tracing
|
340
317
|
# in this thread or not.
|
341
|
-
self.
|
318
|
+
self.current_span ? true : false
|
342
319
|
end
|
343
320
|
|
344
321
|
# Indicates if we're tracing and the current span name matches
|
@@ -349,8 +326,8 @@ module Instana
|
|
349
326
|
# @return [Boolean]
|
350
327
|
#
|
351
328
|
def tracing_span?(name)
|
352
|
-
if self.
|
353
|
-
return self.
|
329
|
+
if self.current_span
|
330
|
+
return self.current_span.name == name
|
354
331
|
end
|
355
332
|
false
|
356
333
|
end
|
@@ -360,8 +337,8 @@ module Instana
|
|
360
337
|
# @return [SpanContext] or nil if not tracing
|
361
338
|
#
|
362
339
|
def context
|
363
|
-
return
|
364
|
-
self.
|
340
|
+
return unless self.current_span
|
341
|
+
self.current_span.context
|
365
342
|
end
|
366
343
|
|
367
344
|
# Take the current trace_id and convert it to a header compatible
|
@@ -370,7 +347,11 @@ module Instana
|
|
370
347
|
# @return [String] a hexadecimal representation of the current trace ID
|
371
348
|
#
|
372
349
|
def trace_id_header
|
373
|
-
|
350
|
+
if self.current_span
|
351
|
+
self.current_span.context.trace_id_header
|
352
|
+
else
|
353
|
+
""
|
354
|
+
end
|
374
355
|
end
|
375
356
|
|
376
357
|
# Take the current span_id and convert it to a header compatible
|
@@ -379,39 +360,33 @@ module Instana
|
|
379
360
|
# @return [String] a hexadecimal representation of the current span ID
|
380
361
|
#
|
381
362
|
def span_id_header
|
382
|
-
|
363
|
+
if self.current_span
|
364
|
+
self.current_span.context.span_id_header
|
365
|
+
else
|
366
|
+
""
|
367
|
+
end
|
383
368
|
end
|
384
369
|
|
385
370
|
# Returns the trace ID for the active trace (if there is one),
|
386
371
|
# otherwise nil.
|
387
372
|
#
|
388
373
|
def trace_id
|
389
|
-
self.
|
374
|
+
self.current_span ? self.current_span.id : nil
|
375
|
+
::Instana.logger.debug("tracer.trace_id will deprecated in a future version.")
|
390
376
|
end
|
391
377
|
|
392
378
|
# Returns the current [Span] ID for the active trace (if there is one),
|
393
379
|
# otherwise nil.
|
394
380
|
#
|
395
381
|
def span_id
|
396
|
-
self.
|
397
|
-
|
398
|
-
|
399
|
-
# Helper method to retrieve the currently active span for the active trace.
|
400
|
-
#
|
401
|
-
def current_span
|
402
|
-
self.current_trace ? self.current_trace.current_span : nil
|
403
|
-
end
|
404
|
-
|
405
|
-
# Indicates if the name of the current span matches <candidate>
|
406
|
-
#
|
407
|
-
def current_span_name?(candidate)
|
408
|
-
self.current_trace && self.current_trace.current_span.name == candidate.to_sym
|
382
|
+
self.current_span ? self.current_span.span_id : nil
|
383
|
+
::Instana.logger.debug("tracer.span_id will deprecated in a future version.")
|
409
384
|
end
|
410
385
|
|
411
386
|
# Used in the test suite, this resets the tracer to non-tracing state.
|
412
387
|
#
|
413
388
|
def clear!
|
414
|
-
self.
|
389
|
+
self.current_span = nil
|
415
390
|
end
|
416
391
|
end
|
417
392
|
end
|