lib/opentelemetry/instrumentation/sidekiq/middlewares/server/tracer_middleware.rb in opentelemetry-instrumentation-sidekiq-0.12.0 vs lib/opentelemetry/instrumentation/sidekiq/middlewares/server/tracer_middleware.rb in opentelemetry-instrumentation-sidekiq-0.13.0
- old
+ new
@@ -13,14 +13,17 @@
# by way of its middleware system
class TracerMiddleware
def call(_worker, msg, _queue)
parent_context = OpenTelemetry.propagation.text.extract(msg)
tracer.in_span(
- msg['wrapped']&.to_s || msg['class'],
+ 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' => msg['queue'],
+ 'messaging.destination_kind' => 'queue'
},
with_parent: parent_context,
kind: :consumer
) do |span|
span.add_event('created_at', timestamp: msg['created_at'])
@@ -28,9 +31,21 @@
yield
end
end
private
+
+ def span_name(msg)
+ if config[:enable_job_class_span_names]
+ "#{msg['wrapped']&.to_s || msg['class']} process"
+ else
+ "#{msg['queue']} process"
+ end
+ end
+
+ def config
+ Sidekiq::Instrumentation.instance.config
+ end
def tracer
Sidekiq::Instrumentation.instance.tracer
end
end