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

Omit _dd.span_sampling.max_per_second when not configured #2715

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
6 changes: 3 additions & 3 deletions lib/datadog/tracing/sampling/span/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Rule
def initialize(
matcher,
sample_rate: Span::Ext::DEFAULT_SAMPLE_RATE,
rate_limit: Span::Ext::DEFAULT_MAX_PER_SECOND
rate_limit: nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. Why demote this from constructor args to constructor body?

Copy link
Member Author

@marcotc marcotc Mar 27, 2023

Choose a reason for hiding this comment

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

I need to know when rate_limit was not set (thus nil).

Before, it would fall back to the default unlimited value -1, but then I can't tell if the user has explicitly set -1 or not set anything at all.

We only want to remove the span_op.set_metric(Span::Ext::TAG_MAX_PER_SECOND, ... tag if the user did not provide a rate_limit.

)

@matcher = matcher
Expand All @@ -35,7 +35,7 @@ def initialize(
# The RateSampler initializer enforces non-zero, falling back to 100% sampling
# if zero is provided.
@sampler.sample_rate = sample_rate
@rate_limiter = Sampling::TokenBucket.new(rate_limit)
@rate_limiter = Sampling::TokenBucket.new(rate_limit || Span::Ext::DEFAULT_MAX_PER_SECOND)
end

# This method should only be invoked for spans that are part
Expand All @@ -61,7 +61,7 @@ def sample!(span_op)
if @sampler.sample?(span_op) && @rate_limiter.allow?(1)
span_op.set_metric(Span::Ext::TAG_MECHANISM, Sampling::Ext::Mechanism::SPAN_SAMPLING_RATE)
span_op.set_metric(Span::Ext::TAG_RULE_RATE, @sample_rate)
span_op.set_metric(Span::Ext::TAG_MAX_PER_SECOND, @rate_limit)
span_op.set_metric(Span::Ext::TAG_MAX_PER_SECOND, @rate_limit) if @rate_limit
:kept
else
:rejected
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def agent_receives_span_step3(previous_success)
it do
expect(single_sampled_span.get_metric('_dd.span_sampling.mechanism')).to eq(8)
expect(single_sampled_span.get_metric('_dd.span_sampling.rule_rate')).to eq(1.0)
expect(single_sampled_span.get_metric('_dd.span_sampling.max_per_second')).to eq(-1)
Copy link
Member

Choose a reason for hiding this comment

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

Should we add test that checks that _dd.span_sampling.max_per_second is set when rate_limit is provided?

expect(single_sampled_span.get_metric('_dd.span_sampling.max_per_second')).to be_nil
expect(local_root_span.get_tag('_dd.p.dm')).to eq('-8')
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/datadog/tracing/sampling/span/rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
end

it 'sets rate limit unlimited' do
expect(rule.rate_limit).to eq(-1)
expect(Datadog::Tracing::Sampling::TokenBucket).to receive(:new).with(-1)
expect(rule.rate_limit).to be_nil
end
end
end
Expand Down