@@ -31,11 +31,13 @@ def call(_worker, msg, _queue)
3131 end
3232
3333 extracted_context = OpenTelemetry . propagation . extract ( msg )
34+ created_at = time_from_timestamp ( msg [ 'created_at' ] )
35+ enqueued_at = time_from_timestamp ( msg [ 'created_at' ] )
3436 OpenTelemetry ::Context . with_current ( extracted_context ) do
3537 if instrumentation_config [ :propagation_style ] == :child
3638 tracer . in_span ( span_name , attributes : attributes , kind : :consumer ) do |span |
37- span . add_event ( 'created_at' , timestamp : msg [ ' created_at' ] )
38- span . add_event ( 'enqueued_at' , timestamp : msg [ ' enqueued_at' ] )
39+ span . add_event ( 'created_at' , timestamp : created_at )
40+ span . add_event ( 'enqueued_at' , timestamp : enqueued_at )
3941 yield
4042 end
4143 else
@@ -44,8 +46,8 @@ def call(_worker, msg, _queue)
4446 links << OpenTelemetry ::Trace ::Link . new ( span_context ) if instrumentation_config [ :propagation_style ] == :link && span_context . valid?
4547 span = tracer . start_root_span ( span_name , attributes : attributes , links : links , kind : :consumer )
4648 OpenTelemetry ::Trace . with_span ( span ) do
47- span . add_event ( 'created_at' , timestamp : msg [ ' created_at' ] )
48- span . add_event ( 'enqueued_at' , timestamp : msg [ ' enqueued_at' ] )
49+ span . add_event ( 'created_at' , timestamp : created_at )
50+ span . add_event ( 'enqueued_at' , timestamp : enqueued_at )
4951 yield
5052 rescue Exception => e # rubocop:disable Lint/RescueException
5153 span . record_exception ( e )
@@ -67,6 +69,15 @@ def instrumentation_config
6769 def tracer
6870 Sidekiq ::Instrumentation . instance . tracer
6971 end
72+
73+ def time_from_timestamp ( timestamp )
74+ if timestamp . is_a? ( Float )
75+ # old format, timestamps were stored as fractional seconds since the epoch
76+ timestamp
77+ else
78+ timestamp / 1000
79+ end
80+ end
7081 end
7182 end
7283 end
0 commit comments