-
Notifications
You must be signed in to change notification settings - Fork 369
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
Fix priority sampling activation #868
Conversation
e4c9b77
to
2c9df11
Compare
2c9df11
to
123baac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some context for some changes.
@@ -69,7 +69,7 @@ class RateByServiceSampler < Sampler | |||
DEFAULT_KEY = 'service:,env:'.freeze | |||
|
|||
def initialize(rate = 1.0, opts = {}) | |||
@env = opts.fetch(:env, Datadog.tracer.tags[:env]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class had a reference to the global tracer which was causing a circular reference and failure to load when priority sampling was enabled by default. This component should not know about the tracer or any global settings, it should be given proper configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same issue while doing sampling work.
I like this solution 👍
@@ -173,7 +173,7 @@ | |||
headers = datum[:headers] | |||
expect(headers).to include(Datadog::Ext::DistributedTracing::HTTP_HEADER_TRACE_ID => span.trace_id.to_s) | |||
expect(headers).to include(Datadog::Ext::DistributedTracing::HTTP_HEADER_PARENT_ID => span.span_id.to_s) | |||
expect(headers).to_not include(Datadog::Ext::DistributedTracing::HTTP_HEADER_SAMPLING_PRIORITY) | |||
expect(headers).to include(Datadog::Ext::DistributedTracing::HTTP_HEADER_SAMPLING_PRIORITY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Evidently our integration tests were expecting sampling priority to be off by default as well...
@@ -25,6 +25,7 @@ | |||
it { expect(trace).to eq(result) } | |||
|
|||
it 'tracks the number of allocations made in the span' do | |||
skip 'Test unstable; improve stability before re-enabling.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been a super flaky test that has been breaking builds; disabled it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it now break builds because of this PR, or has it always been flaky?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always been flaky. It just was breaking the build too many times now when I was trying to fix things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please put into a separate PR
lib/ddtrace/tracer.rb
Outdated
@@ -441,7 +444,8 @@ def activate_priority_sampling!(base_sampler = nil) | |||
@sampler = if base_sampler.is_a?(PrioritySampler) | |||
base_sampler | |||
else | |||
PrioritySampler.new(base_sampler: base_sampler) | |||
PrioritySampler.new(base_sampler: base_sampler, | |||
post_sampler: Datadog::RateByServiceSampler.new(1.0, env: tags[:env])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of https://github.com/DataDog/dd-trace-rb/pull/868/files#diff-075cdbe46a2ed147b75f5da176ae2e88L72
This is how you ensure env is still properly applied from the tracer to the sampler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the env tag is changed after we initialize a priority sampler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't be read; same as it is today.The only difference is maybe you were configuring tags at the same time you activated priority sampling manually, so maybe it would've applied, maybe it wouldn't; depends on the order the settings were applied.
Only conceivable way is to change the value to a lazy Proc
. You could argue that the key_for(span)
function should be this Proc
, and when you define a RateByServiceSampler
, you should provide this proc that acts as means of resolving a key. Which would make this more of a RateByKeySampler
which can optionally configured to use an env
or not, which I think would be a better design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I did a small refactor of the RateByServiceSampler
and changed it to resolve the env from a Proc
. Feel free to take a look.
@@ -25,6 +25,7 @@ | |||
it { expect(trace).to eq(result) } | |||
|
|||
it 'tracks the number of allocations made in the span' do | |||
skip 'Test unstable; improve stability before re-enabling.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it now break builds because of this PR, or has it always been flaky?
The tracer should enable priority sampling by default, but it does not; instead it's only activating priority sampling when
Tracer#configure
was called.This pull request ensures that priority sampling is enabled by default.