Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass trace parent to sidekiq job #1444

Open
kurigashvili-godaddy opened this issue Mar 15, 2024 · 1 comment
Open

Pass trace parent to sidekiq job #1444

kurigashvili-godaddy opened this issue Mar 15, 2024 · 1 comment

Comments

@kurigashvili-godaddy
Copy link

kurigashvili-godaddy commented Mar 15, 2024

Is your feature request related to a problem? Please describe.

I would like an ability to pass trace parent from request to sidekiq job so trace id for request and sidekiq is the same.
This is currently possible in APM for node.js
https://www.elastic.co/guide/en/apm/agent/nodejs/current/message-queues.html

I tried creating transaction in sidekiq middleware like this

ElasticAPM.start_transaction('some-job', 'sidekiq', trace_context: ElasticAPM::TraceContext.new(
    traceparent: ElasticAPM::TraceContext::Traceparent.new(trace_id: trace_parent[:trace_id])
 ))

But APM Sidekiq middleware always runs after and it fails with ExistingTransactionError. If it runs before, it still would have this issue.
https://github.com/elastic/apm-agent-ruby/blob/main/lib/elastic_apm/spies/sidekiq.rb#L32
https://github.com/elastic/apm-agent-ruby/blob/main/lib/elastic_apm/instrumenter.rb#L116

Possible solution

May be you can look for certain parameter on job object and use it to set trace_context parameter.
https://github.com/elastic/apm-agent-ruby/blob/main/lib/elastic_apm/spies/sidekiq.rb#L32

Client middleware can pass it similar to the example here https://github.com/sidekiq/sidekiq/wiki/Middleware#client-middleware

@estolfo
Copy link
Contributor

estolfo commented Mar 28, 2024

Hi @kurigashvili-godaddy thanks for opening this issue. It seems reasonable to support passing the trace context to the sidekiq job. Since you've already identified all the relevant parts of the code, do you want to open a PR to add support?

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

No branches or pull requests

2 participants