lib/opentelemetry/instrumentation/active_job/handlers/perform.rb in opentelemetry-instrumentation-active_job-0.7.7 vs lib/opentelemetry/instrumentation/active_job/handlers/perform.rb in opentelemetry-instrumentation-active_job-0.7.8

- old
+ new

@@ -32,20 +32,21 @@ span_context = OpenTelemetry::Trace.current_span(parent_context).context links = [OpenTelemetry::Trace::Link.new(span_context)] if span_context.valid? && propagation_style == :link span = tracer.start_root_span(span_name, kind: :consumer, attributes: @mapper.call(payload), links: links) end - { span: span, ctx_token: attach_consumer_context(span) } + { span: span, ctx_token: attach_consumer_context(span, parent_context) } end # This method attaches a span to multiple contexts: # 1. Registers the ingress span as the top level ActiveJob span. # This is used later to enrich the ingress span in children, e.g. setting span status to error when a child event like `discard` terminates due to an error # 2. Registers the ingress span as the "active" span, which is the default behavior of the SDK. # @param span [OpenTelemetry::Trace::Span] the currently active span used to record the exception and set the status + # @param parent_context [Context] The context to use as the parent for the consumer context # @return [Numeric] Context token that must be detached when finished - def attach_consumer_context(span) - consumer_context = OpenTelemetry::Trace.context_with_span(span) + def attach_consumer_context(span, parent_context) + consumer_context = OpenTelemetry::Trace.context_with_span(span, parent_context: parent_context) internal_context = OpenTelemetry::Instrumentation::ActiveJob.context_with_span(span, parent_context: consumer_context) OpenTelemetry::Context.attach(internal_context) end end