Skip to content

Commit 47be1d1

Browse files
committed
use the proper timestamps in the client too
1 parent 773f8e7 commit 47be1d1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def call(_worker_class, job, _queue, _redis_pool)
3131

3232
tracer.in_span(span_name, attributes: attributes, kind: :producer) do |span|
3333
OpenTelemetry.propagation.inject(job)
34-
span.add_event('created_at', timestamp: job['created_at'])
34+
span.add_event('created_at', timestamp: time_from_timestamp(job['created_at']))
3535
yield
3636
end
3737
end
@@ -45,6 +45,15 @@ def instrumentation_config
4545
def tracer
4646
Sidekiq::Instrumentation.instance.tracer
4747
end
48+
49+
def time_from_timestamp(timestamp)
50+
if timestamp.is_a?(Float)
51+
# old format, timestamps were stored as fractional seconds since the epoch
52+
timestamp
53+
else
54+
timestamp / 1000
55+
end
56+
end
4857
end
4958
end
5059
end

instrumentation/sidekiq/test/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
_(enqueue_span.attributes['messaging.destination']).must_equal 'default'
4545
_(enqueue_span.attributes['messaging.destination_kind']).must_equal 'queue'
4646
_(enqueue_span.events.size).must_equal(1)
47-
_(enqueue_span.events[0].name).must_equal('created_at')
47+
48+
created_event = enqueue_span.events[0]
49+
_(created_event.name).must_equal('created_at')
50+
_(created_event.timestamp.digits.count).must_equal(19)
4851
end
4952

5053
it 'traces when enqueued with Active Job' do

0 commit comments

Comments
 (0)