lib/opentelemetry/instrumentation/active_job/handlers/perform.rb in opentelemetry-instrumentation-active_job-0.7.3 vs lib/opentelemetry/instrumentation/active_job/handlers/perform.rb in opentelemetry-instrumentation-active_job-0.7.4
- old
+ new
@@ -8,19 +8,10 @@
module Instrumentation
module ActiveJob
module Handlers
# Handles perform.active_job to generate ingress spans
class Perform < Default
- def initialize(...)
- super
- @span_name_formatter = if @config[:span_naming] == :job_class
- ->(job) { "#{job.class.name} process" }
- else
- ->(job) { "#{job.queue_name} process" }
- end
- end
-
# Overrides the `Default#start_span` method to create an ingress span
# and registers it with the current context
#
# @param name [String] of the Event
# @param id [String] of the event
@@ -28,11 +19,11 @@
# @return [Hash] with the span and generated context tokens
def start_span(name, _id, payload)
job = payload.fetch(:job)
parent_context = OpenTelemetry.propagation.extract(job.__otel_headers)
- span_name = @span_name_formatter.call(job)
+ span_name = span_name(job)
# TODO: Refactor into a propagation strategy
propagation_style = @config[:propagation_style]
if propagation_style == :child
span = tracer.start_span(span_name, kind: :consumer, attributes: @mapper.call(payload))
@@ -54,9 +45,21 @@
def attach_consumer_context(span)
consumer_context = OpenTelemetry::Trace.context_with_span(span)
internal_context = OpenTelemetry::Instrumentation::ActiveJob.context_with_span(span, parent_context: consumer_context)
OpenTelemetry::Context.attach(internal_context)
+ end
+
+ private
+
+ def span_name(job)
+ prefix = if @config[:span_naming] == :job_class
+ job.class.name
+ else
+ job.queue_name
+ end
+
+ "#{prefix} process"
end
end
end
end
end