Class: OpenTelemetry::Instrumentation::Sidekiq::Middlewares::Server::TracerMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/sidekiq/middlewares/server/tracer_middleware.rb

Overview

TracerMiddleware propagates context and instruments Sidekiq requests by way of its middleware system

Instance Method Summary collapse

Instance Method Details

#call(_worker, msg, _queue) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/opentelemetry/instrumentation/sidekiq/middlewares/server/tracer_middleware.rb', line 15

def call(_worker, msg, _queue)
  parent_context = OpenTelemetry.propagation.extract(msg)
  tracer.in_span(
    span_name(msg),
    attributes: {
      'messaging.system' => 'sidekiq',
      'messaging.sidekiq.job_class' => msg['wrapped']&.to_s || msg['class'],
      'messaging.message_id' => msg['jid'],
      'messaging.destination' => msg['queue'],
      'messaging.destination_kind' => 'queue'
    },
    with_parent: parent_context,
    kind: :consumer
  ) do |span|
    span.add_event('created_at', timestamp: msg['created_at'])
    span.add_event('enqueued_at', timestamp: msg['enqueued_at'])
    yield
  end
end