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

Fix priority sampling activation #868

Merged
merged 3 commits into from
Nov 26, 2019
Merged

Conversation

delner
Copy link
Contributor

@delner delner commented Nov 22, 2019

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.

@delner delner added bug Involves a bug core Involves Datadog core libraries labels Nov 22, 2019
@delner delner requested review from marcotc, brettlangdon and a team November 22, 2019 21:21
@delner delner self-assigned this Nov 22, 2019
@delner delner added this to In review in Active work Nov 22, 2019
@delner delner force-pushed the fix/priority_sampling_activation branch from e4c9b77 to 2c9df11 Compare November 22, 2019 21:39
@delner delner force-pushed the fix/priority_sampling_activation branch from 2c9df11 to 123baac Compare November 22, 2019 21:46
Copy link
Contributor Author

@delner delner left a 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])
Copy link
Contributor Author

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.

Copy link
Member

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)
Copy link
Contributor Author

@delner delner Nov 22, 2019

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.'
Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

@@ -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]))
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@delner delner Nov 23, 2019

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.'
Copy link
Member

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?

@delner delner merged commit f8ca58e into master Nov 26, 2019
Active work automation moved this from In review to Merged & awaiting release Nov 26, 2019
@delner delner deleted the fix/priority_sampling_activation branch November 26, 2019 17:55
@delner delner modified the milestones: 0.26.1, 0.29.1 Nov 26, 2019
@delner delner moved this from Merged & awaiting release to Released in Active work Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug core Involves Datadog core libraries
Projects
Active work
  
Released
Development

Successfully merging this pull request may close these issues.

None yet

3 participants