Class: OpenTelemetry::Instrumentation::ActiveJob::Handlers::Enqueue

Inherits:
Default
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb

Overview

Handles enqueue.active_job and enqueue_at.active_job to generate egress spans

Instance Method Summary collapse

Methods inherited from Default

#finish, #finish_span, #on_exception, #start, #tracer

Constructor Details

#initializeEnqueue

Returns a new instance of Enqueue.



13
14
15
16
17
18
19
20
# File 'lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb', line 13

def initialize(...)
  super
  @span_name_formatter = if @config[:span_naming] == :job_class
                           ->(job) { "#{job.class.name} publish" }
                         else
                           ->(job) { "#{job.queue_name} publish" }
                         end
end

Instance Method Details

#start_span(name, _id, payload) ⇒ Hash

Overrides the Default#start_span method to create an egress span and registers it with the current context

Parameters:

  • name (String)

    of the Event

  • id (String)

    of the event

  • payload (Hash)

    containing job run information

Returns:

  • (Hash)

    with the span and generated context tokens



29
30
31
32
33
34
# File 'lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb', line 29

def start_span(name, _id, payload)
  job = payload.fetch(:job)
  span = tracer.start_span(@span_name_formatter.call(job), kind: :producer, attributes: @mapper.call(payload))
  OpenTelemetry.propagation.inject(job.__otel_headers) # This must be transmitted over the wire
  { span: span, ctx_token: OpenTelemetry::Context.attach(OpenTelemetry::Trace.context_with_span(span)) }
end