Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def call(_worker, msg, _queue)
end

extracted_context = OpenTelemetry.propagation.extract(msg)
created_at = time_from_timestamp(msg['created_at'])
enqueued_at = time_from_timestamp(msg['created_at'])
created_at = time_from_timestamp(msg['created_at'] || msg['enqueued_at'] || 0)
enqueued_at = time_from_timestamp(msg['enqueued_at'] || 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this end up loosing meaning? Would it not be better to omit the span events in these cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably! I'll admit I'm not an opentelemetry expert; just trying to fix the crash. 🙂

Would it be more advisable to let time_from_timestamp handle/return nil and skip the add_event in those cases?

I think letting the created_at default to enqueued_at when not specified can still be useful, but maybe not so much the 0 default (which I only selected since Sidekiq's API does that).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, If the value is not set, we shouldn't have any event. Not provide misleading data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xathien think then that it's best to check if the values are present and only add the events if that's the case. I don't think the timestamp helper should tolerate nil values at this time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me! I've updated the change accordingly.

OpenTelemetry::Context.with_current(extracted_context) do
if instrumentation_config[:propagation_style] == :child
tracer.in_span(span_name, attributes: attributes, kind: :consumer) do |span|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,31 @@
_(job_span.attributes['messaging.operation']).must_equal 'process'
end

it 'traces when enqueued through another system' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name this as "when enqueued with minimal data"

payload = { 'queue' => 'default', 'args' => [], 'class' => SimpleJob, 'enqueued_at' => Time.current, 'jid' => '4' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't enqueued_at be removed here too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exq supplies this one, but not created_at from what I can tell. In addition, Sidekiq::Client#raw_push adds enqueued_at on its own. I could try doing some shenanigans to push the job directly to Redis, but I'm not sure that effort would be worth the slight test improvement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, it's not about Exq. It's about what any custom library could do. If it's possible to enqueue a job and have it processed by sidekiq without an `enqueued_at, then we should handle it.
If sidekiq would auto-add it, or reject processing it then, we're good.

Sidekiq::Client.new.send(:raw_push, [payload])
Sidekiq::Worker.drain_all

_(job_span.name).must_equal 'default process'
_(job_span.kind).must_equal :consumer
_(job_span.attributes['messaging.system']).must_equal 'sidekiq'
_(job_span.attributes['messaging.sidekiq.job_class']).must_equal 'SimpleJob'
_(job_span.attributes['messaging.message_id']).must_equal '4'
_(job_span.attributes['messaging.destination']).must_equal 'default'
_(job_span.attributes['messaging.destination_kind']).must_equal 'queue'
_(job_span.attributes['messaging.operation']).must_equal 'process'
_(job_span.attributes['peer.service']).must_be_nil
_(job_span.events.size).must_equal(2)

created_event = job_span.events[0]
_(created_event.name).must_equal('created_at')
_(created_event.timestamp.digits.count).must_equal(19)

enqueued_event = job_span.events[1]
_(enqueued_event.name).must_equal('enqueued_at')
_(enqueued_event.timestamp.digits.count).must_equal(19)
end

it 'defaults to using links to the enqueing span but does not continue the trace' do
SimpleJob.perform_async
SimpleJob.drain
Expand Down