Skip to content

Pass trace parent to sidekiq job #1444

@kurigashvili-godaddy

Description

@kurigashvili-godaddy

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions