Skip to content

Configuring Tracing for Sidekiq #1586

@choxi

Description

@choxi

What is the recommended way to pass a trace ID from Rails to a Sidekiq worker? I have this configuration:

# config/initializers/sentry.rb

Sentry.init do |config|
  config.breadcrumbs_logger = [:active_support_logger, :http_logger]

  # Ignore 404s
  config.excluded_exceptions += ['ActionController::RoutingError']

  config.traces_sample_rate = 1.0
end

and

# Gemfile
gem "sentry-rails"
gem "sentry-sidekiq"

When I queue a Sidekiq job:

class PostsController < ApplicationController
  def create
    # How do I pass the trace_id to the worker?
    PostsWorker.perform_async(post_id, trace_id)
  end
end

class PostsWorker
  include Sidekiq::Worker
  
  def perform(post_id, trace_id)
    # How do I set the trace_id in the worker?
    Sentry.set_trace_id(trace_id)
  end
end

It currently starts a separate trace for the controller and the worker, but I'd like the worker to belong to the same trace as the request. Is there a way to do this?

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions