Class: OpenTelemetry::Instrumentation::Sidekiq::Middlewares::Client::TracerMiddleware

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#call(_worker_class, job, _queue, _redis_pool) ⇒ Object

rubocop:disable Metrics/AbcSize



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

def call(_worker_class, job, _queue, _redis_pool) # rubocop:disable Metrics/AbcSize
  attributes = {
    'messaging.system' => 'sidekiq',
    'messaging.sidekiq.job_class' => job['wrapped']&.to_s || job['class'],
    'messaging.message_id' => job['jid'],
    'messaging.destination' => job['queue'],
    'messaging.destination_kind' => 'queue'
  }
  attributes['peer.service'] = instrumentation_config[:peer_service] if instrumentation_config[:peer_service]

  span_name = case instrumentation_config[:span_naming]
              when :job_class then "#{job['wrapped']&.to_s || job['class']} send"
              else "#{job['queue']} send"
              end

  tracer.in_span(span_name, attributes: attributes, kind: :producer) do |span|
    OpenTelemetry.propagation.inject(job)
    span.add_event('created_at', timestamp: job['created_at'])
    yield
  end
end