-
Notifications
You must be signed in to change notification settings - Fork 440
fix(sampling): ensure agent based sampling is not reset after forking and on tracer.configure #13560
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
base: main
Are you sure you want to change the base?
Conversation
|
Bootstrap import analysisComparison of import times between this PR and base. SummaryThe average import time from this PR is: 275 ± 4 ms. The average import time from base is: 277 ± 4 ms. The import time difference between this PR and base is: -1.1 ± 0.2 ms. Import time breakdownThe following import paths have grown:
|
BenchmarksBenchmark execution time: 2025-06-17 04:04:14 Comparing candidate commit 7101cbd in PR branch Found 0 performance improvements and 5 performance regressions! Performance is the same for 556 metrics, 3 unstable metrics. scenario:iastaspects-upper_aspect
scenario:iastaspectsospath-ospathjoin_aspect
scenario:iastaspectsospath-ospathsplitext_aspect
scenario:telemetryaddmetric-1-distribution-metric-1-times
scenario:telemetryaddmetric-flush-1-metric
|
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.
would be nice to have a regression test for this, otherwise lgtm
4d50f44
to
7e14fee
Compare
6afec51
to
cbfe917
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.
Nice work. Is there a test for how this works in subprocesses that I'm missing?
ddtrace/_trace/sampler.py
Outdated
@@ -101,7 +102,7 @@ def __init__( | |||
else: | |||
self.rules: List[SamplingRule] = rules or [] | |||
# Set Agent based samplers | |||
self._by_service_samplers: Dict[str, RateSampler] = {} | |||
self._agent_sampling_rules = agent_sampling_rules or {} |
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.
_agent_based_samplers
might be better here, since the use of the term "rules" conflicts with the way it's used elsewhere in the library as opposed to "sampler".
ef76a21
to
4d311a8
Compare
return trace | ||
|
||
class UserProc(TraceProcessor) | ||
def process_trace(self, trace): |
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.
⚪ Code Quality Violation
class names should be PascalCase (...read more)
Class names should be PascalCase
and not camelCase
or snake_case
.
Learn More
|
||
class UserProc(TraceProcessor) | ||
def process_trace(self, trace): | ||
return trace |
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.
376430f
to
7101cbd
Compare
Builds on 7fbdc9f
Fix: Avoids reinitializing the SpanAggregator on
tracer.configure(...)
and when an application forks. InsteadSpanAggregator._reset()
is called. This operation ensures global configurations are re-applied, trace buffer is reset, and trace writer is recreated. This ensures agent based sampling rules are not reset.Clean up
writer
parameter fromSpanAggregator.__init__(...)
with this change the intialization of the global writer is an implementation detail of the SpanAggregator. There is no longer a need to supply theSpanAggregator
with a writer on the initialization of the global tracer._default_span_processors_factory
. With this change the global tracer's SpanAggregator is never re-created. It's only modified whentracer.configure(..)
is used.DatadogSampler._service_based_samplers
property toDatadogSampler._agent_sampling_rules
to improve clarity. These sampling rules are no longer supplied via environment variables or a programatic api, they can only be set by the Datadog Agent.SpanAggregator.trace_proccessors
into two propertiesSpanAggregator.dd_proccessors
andSpanAggregator.user_processors
.SpanAggregator.users_proccessors
is set after application startup viaTracer.configure(..)
whileSpanAggregator.dd_proccessors
is internal to the ddtrace library and should only be set by ddtrace components. This separation allows us to avoid recreating all trace processors whentracer.configure()
is called.Checklist
Reviewer Checklist