lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb in opentelemetry-instrumentation-sidekiq-0.12.0 vs lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb in opentelemetry-instrumentation-sidekiq-0.13.0
- old
+ new
@@ -12,23 +12,38 @@
# TracerMiddleware propagates context and instruments Sidekiq client
# by way of its middleware system
class TracerMiddleware
def call(_worker_class, job, _queue, _redis_pool)
tracer.in_span(
- job['wrapped']&.to_s || job['class'],
+ span_name(job),
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' => job['queue'],
+ 'messaging.destination_kind' => 'queue'
},
kind: :producer
) do |span|
OpenTelemetry.propagation.text.inject(job)
span.add_event('created_at', timestamp: job['created_at'])
yield
end
end
private
+
+ def span_name(job)
+ if config[:enable_job_class_span_names]
+ "#{job['wrapped']&.to_s || job['class']} enqueue"
+ else
+ "#{job['queue']} send"
+ end
+ end
+
+ def config
+ Sidekiq::Instrumentation.instance.config
+ end
def tracer
Sidekiq::Instrumentation.instance.tracer
end
end