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

Add sidekiq config propagate_traces to control trace header injection #2588

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

- Add new sidekiq config `report_only_dead_jobs` ([#2581](https://github.com/getsentry/sentry-ruby/pull/2581))
- Add `max_nesting` of 10 to breadcrumbs data serialization ([#2583](https://github.com/getsentry/sentry-ruby/pull/2583))
- Add sidekiq config `propagate_traces` to control trace header injection ([#2588](https://github.com/getsentry/sentry-ruby/pull/2588))

If you use schedulers you can get one large trace with all your jobs which is undesirable.
We recommend using the following to propagate traces only from the Rails server and not elsewhere.

```ruby
config.sidekiq.propagate_traces = false unless Rails.const_defined?('Server')
```

### Bug Fixes

Expand Down
4 changes: 4 additions & 0 deletions sentry-sidekiq/lib/sentry/sidekiq/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ class Configuration
# Only report jobs that don't have `dead: false` set in the job's `sidekiq_options`
attr_accessor :report_only_dead_jobs

# Whether we should inject headers while enqueuing the job in order to have a connected trace
attr_accessor :propagate_traces

def initialize
@report_after_job_retries = false
@report_only_dead_jobs = false
@propagate_traces = true
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ def call(worker_class, job, queue, _redis_pool)

user = Sentry.get_current_scope.user
job["sentry_user"] = user unless user.empty?
job["trace_propagation_headers"] ||= Sentry.get_trace_propagation_headers

if Sentry.configuration.sidekiq.propagate_traces
job["trace_propagation_headers"] ||= Sentry.get_trace_propagation_headers
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this a breaking change in a way? Previously it would do it unconditionally. Now you have to explicitly enable it. I understand that the original behavior was problematic though so maybe it's fine?

Copy link
Member Author

Choose a reason for hiding this comment

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

it defaults to true


Sentry.with_child_span(op: "queue.publish", description: worker_class.to_s) do |span|
set_span_data(span, id: job["jid"], queue: queue)
Expand Down
12 changes: 12 additions & 0 deletions sentry-sidekiq/spec/sentry/sidekiq/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@
expect(subject.report_after_job_retries).to eq(false)
end
end

describe "#report_only_dead_jobs" do
it "has correct default value" do
expect(subject.report_only_dead_jobs).to eq(false)
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems unrelated?

Copy link
Member Author

Choose a reason for hiding this comment

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

was missing so just added it


describe "#propagate_traces" do
it "has correct default value" do
expect(subject.propagate_traces).to eq(true)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,19 @@
expect(event.spans[0][:data]['messaging.message.id']).to eq(message_id)
expect(event.spans[0][:data]['messaging.destination.name']).to eq('default')
end

it "does not propagate headers with propagate_traces = false" do
perform_basic_setup do |config|
config.traces_sample_rate = 1.0
config.sidekiq.propagate_traces = false
end

Sentry.get_current_scope.set_span(transaction)

client.push('queue' => 'default', 'class' => HappyWorker, 'args' => [])

expect(queue.size).to be(1)
expect(queue.first["trace_propagation_headers"]).to be_nil
end
end
end
Loading