Skip to content

Commit ef28d89

Browse files
github-actions[bot]ZStriker19juanjuxchristophe-papaziangnufede
authored
fix(tracing): return trace regardless of sampling decision unless stats comp enabled backport 1.20 (#8399)
Note this backport modifies a snapshot file in addition to the backport, since that was backported to 1.20 originally, but never ran due to test suite issues. Backport 9427b01 from #8385 to 1.20. Return trace regardless of sampling decision unless stats computation is on. ## 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] Risks are described (performance impact, potential for breakage, maintainability) - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [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)) - [x] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. - [x] If change 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`. ## Reviewer Checklist - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] 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) --------- Co-authored-by: Zachary Groves <[email protected]> Co-authored-by: Juanjo Alvarez Martinez <[email protected]> Co-authored-by: Christophe Papazian <[email protected]> Co-authored-by: Federico Mon <[email protected]> Co-authored-by: ZStriker19 <[email protected]>
1 parent f1c839f commit ef28d89

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

ddtrace/internal/processor/trace.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ def process_trace(self, trace):
9595

9696
return single_spans or None
9797

98-
for span in trace:
99-
if span.sampled:
100-
return trace
98+
return trace
10199

102-
log.debug("dropping trace %d with %d spans", trace[0].trace_id, len(trace))
100+
log.debug("dropping trace %d with %d spans", trace[0].trace_id, len(trace))
103101

104102
return None
105103

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
tracing: This fix resolves an issue where previously some traces that were not sampled were not sent to the trace-agent, possibly affecting metrics.
5+
With this fix, all traces are sent to the agent.
6+
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
[[
22
{
33
"name": "trace8",
4-
"service": "",
4+
"service": null,
55
"resource": "trace8",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 0,
9-
"type": "",
10-
"error": 0,
119
"meta": {
12-
"_dd.p.tid": "65cbd89000000000",
1310
"language": "python",
14-
"runtime-id": "7a2aa1b276634a76b25c928fffea4cdc"
11+
"runtime-id": "3fca1d80c0964fbbb4f687fc836bc225"
1512
},
1613
"metrics": {
1714
"_dd.top_level": 1,
1815
"_dd.tracer_kr": 1.0,
19-
"process_id": 83161
16+
"process_id": 55908
2017
},
21-
"duration": 64000,
22-
"start": 1707858064774777000
18+
"duration": 127000,
19+
"start": 1709568577619719000
2320
},
2421
{
2522
"name": "child",
26-
"service": "",
23+
"service": null,
2724
"resource": "child",
2825
"trace_id": 0,
2926
"span_id": 2,
3027
"parent_id": 1,
31-
"type": "",
32-
"error": 0,
33-
"duration": 13000,
34-
"start": 1707858064774816000
28+
"duration": 59000,
29+
"start": 1709568577619765000
3530
}]]

tests/tracer/test_sampler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ def test_sample_rate_deviation(self):
104104
span.finish()
105105

106106
samples = tracer.pop()
107-
107+
# non sampled spans do not have sample rate applied
108+
sampled_spans = [s for s in samples if s.sampled]
108109
assert (
109-
samples[0].get_metric(SAMPLE_RATE_METRIC_KEY) == sample_rate
110+
sampled_spans[0].get_metric(SAMPLE_RATE_METRIC_KEY) == sample_rate
110111
), "Sampled span should have sample rate properly assigned"
111112

112-
deviation = abs(len(samples) - (iterations * sample_rate)) / (iterations * sample_rate)
113+
deviation = abs(len(sampled_spans) - (iterations * sample_rate)) / (iterations * sample_rate)
113114
assert (
114115
deviation < 0.05
115116
), "Actual sample rate should be within 5 percent of set sample " "rate (actual: %f, set: %f)" % (
@@ -131,7 +132,7 @@ def test_deterministic_behavior(self):
131132
assert (
132133
len(samples) <= 1
133134
), "evaluating sampling rules against a span should result in either dropping or not dropping it"
134-
sampled = 1 == len(samples)
135+
sampled = 1 == len([sample for sample in samples if sample.sampled is True])
135136
for _ in range(10):
136137
other_span = Span(str(i), trace_id=span.trace_id)
137138
assert sampled == tracer._sampler.sample(

tests/tracer/test_tracer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,9 @@ def test_spans_sampled_out(tracer, test_spans):
17391739
span.sampled = False
17401740

17411741
spans = test_spans.pop()
1742-
assert len(spans) == 0
1742+
assert len(spans) == 3
1743+
for span in spans:
1744+
assert span.sampled is False
17431745

17441746

17451747
def test_spans_sampled_one(tracer, test_spans):

0 commit comments

Comments
 (0)