Skip to content

Conversation

@xathien
Copy link

@xathien xathien commented Nov 21, 2025

Exq doesn't seem to pass "created_at" with its messages. Current Sidekiq API defaults created_at to enqueued_at or 0 if it's not available, so we can mimic that method for safely defaulting these values.

Fixes #1795

Exq doesn't seem to pass "created_at" with its messages. [Current Sidekiq API](https://github.com/sidekiq/sidekiq/blob/f9e0a026543c93ae49c1d1d41c6592d2877d318a/lib/sidekiq/api.rb#L456) defaults `created_at` to `enqueued_at` or `0` if it's not available, so we can mimic that method for safely defaulting thee values.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 21, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: arielvalentin / name: Ariel Valentin (38c1812)
  • ✅ login: xathien / name: Zack Young (040c291, ed95854)

Comment on lines 34 to 35
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.

Copy link
Member

@dmathieu dmathieu left a comment

Choose a reason for hiding this comment

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

This will need a changelog entry

_(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"

end

it 'traces when enqueued through another system' do
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.

@arielvalentin
Copy link
Contributor

arielvalentin commented Nov 23, 2025

This will need a changelog entry

@dmathieu our release tooling auto-generates the changelog based on the title of the PR/merge commit so there isn't a need to create a manual entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sidekiq timestamp incompatibility results in NoMethodError

3 participants