Skip to content

Commit 4e04d3c

Browse files
authored
chore(sampling): only one tracer instance is used per span sampling test (#6935)
Before, we were creating a new tracer instance each time we tried to generate a span in a test. With this change we make sure to use the same tracer instance per test. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [ ] Title is accurate. - [ ] No unnecessary changes are introduced. - [ ] Description motivates each change. - [ ] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Testing strategy adequately addresses listed risk(s). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] Release note makes sense to a user of the library. - [ ] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [ ] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [ ] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [ ] This PR doesn't touch any of that.
1 parent f1b3e09 commit 4e04d3c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/tracer/test_single_span_sampling_rules.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,35 +316,39 @@ def test_single_span_rule_unsupported_pattern_escape_character_literal_evaluatio
316316

317317
def test_multiple_span_rule_match():
318318
rule = SpanSamplingRule(service="test_service", name="test_name", sample_rate=1.0, max_per_second=-1)
319+
tracer = DummyTracer()
319320
for _ in range(10):
320-
span = traced_function(rule)
321+
span = traced_function(rule, tracer)
321322
assert_sampling_decision_tags(span)
322323

323324

324325
def test_single_span_rules_not_applied_if_span_dropped_by_single_span_rate_limiter():
325326
rule = SpanSamplingRule(service="test_service", name="test_name", sample_rate=1.0, max_per_second=0)
327+
tracer = DummyTracer()
326328
for _ in range(10):
327-
span = traced_function(rule)
329+
span = traced_function(rule, tracer)
328330
assert_sampling_decision_tags(span, sample_rate=None, mechanism=None, limit=None)
329331

330332

331333
def test_max_per_sec_with_is_allowed_check():
332334
rule = SpanSamplingRule(service="test_service", name="test_name", sample_rate=1.0, max_per_second=2)
333335
# Make spans till we hit the limit, then make a span while the limit is hit and make sure tags were not added.
336+
tracer = DummyTracer(rule)
334337
while True:
335-
span = traced_function(rule)
338+
span = traced_function(rule, tracer)
336339
if not rule._limiter._is_allowed(span.start_ns):
337340
break
338341
assert_sampling_decision_tags(span, limit=2)
339342

340-
rate_limited_span = traced_function(rule)
343+
rate_limited_span = traced_function(rule, tracer)
341344
assert_sampling_decision_tags(rate_limited_span, sample_rate=None, mechanism=None, limit=None)
342345

343346

344347
def test_max_per_sec_with_predetermined_number_of_spans():
345348
rule = SpanSamplingRule(service="test_service", name="test_name", sample_rate=1.0, max_per_second=2)
349+
tracer = DummyTracer()
346350
for i in range(3):
347-
span = traced_function(rule)
351+
span = traced_function(rule, tracer)
348352
if i < 2:
349353
assert_sampling_decision_tags(span, limit=2)
350354
else:

0 commit comments

Comments
 (0)