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

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::ClientMiddleware
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



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

def call(_worker_class, job, _queue, _redis_pool)
  attributes = {
    SemanticConventions::Trace::MESSAGING_SYSTEM => 'sidekiq',
    'messaging.sidekiq.job_class' => job['wrapped']&.to_s || job['class'],
    SemanticConventions::Trace::MESSAGING_MESSAGE_ID => job['jid'],
    SemanticConventions::Trace::MESSAGING_DESTINATION => job['queue'],
    SemanticConventions::Trace::MESSAGING_DESTINATION_KIND => 'queue'
  }
  attributes[SemanticConventions::Trace::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']} publish"
              else "#{job['queue']} publish"
              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