21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/instana/instrumentation/active_job.rb', line 21
def self.prepended(target)
target.around_enqueue do |job, block|
tags = {
activejob: {
queue: job.queue_name,
job: job.class.to_s,
action: :enqueue,
job_id: job.job_id
}
}
::Instana.tracer.in_span(:activejob, attributes: tags) do
context = ::Instana.tracer.context
job.arguments.append({
instana_context: context ? context.to_hash : nil
})
block.call
end
end
target.around_perform do |job, block|
tags = {
activejob: {
queue: job.queue_name,
job: job.class.to_s,
action: :perform,
job_id: job.job_id
}
}
incoming_context = if job.arguments.is_a?(Array) && job.arguments.last.is_a?(Hash) && job.arguments.last.key?(:instana_context)
instana_context = job.arguments.last[:instana_context]
job.arguments.pop
instana_context ? ::Instana::SpanContext.new(trace_id: instana_context[:trace_id], span_id: instana_context[:span_id]) : nil
end
Trace.with_span(OpenTelemetry::Trace.non_recording_span(incoming_context)) do
::Instana.tracer.in_span(:activejob, attributes: tags) do
block.call
end
end
end
end
|