-
Notifications
You must be signed in to change notification settings - Fork 133
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
Trace sample rate does not work for child traces #2064
Comments
Hey @shagedorn 👋. Thanks a lot for providing the reproduction steps; that’s always incredibly helpful. However, in this case, I couldn't reproduce the issue. I tried the following minimal setup with a trace import DatadogCore
import DatadogTrace
Datadog.initialize(
with: .init(clientToken: "<client-token>", env: "<env>"),
trackingConsent: .granted
)
Datadog.verbosityLevel = .debug
Trace.enable(
with: .init(sampleRate: 0)
)
for _ in (0..<10) {
let span1 = Tracer.shared().startSpan(operationName: "parent").setActive()
let span2 = Tracer.shared().startSpan(operationName: "child").setActive()
span2.finish()
span1.finish()
} No spans were indexed. Here are a few important points to keep in mind about APM sampling, particularly when using a
|
Hi @ncreated, thanks a lot for all that context 🙏🏻 There's some new information in here, we're re-evaluating our initial report and will follow up with an update shortly! |
Soo… we were blissfully unaware of head-based sampling. Thank you for clarifying this!
This is also helpful to know, thank you!
Thank you, we'll clean this up 🙏🏻 ✅ With this context, our original bug report isn't valid anymore. ❓ However, I tried your example (and our own code) and I feel like there's an opposite bug, or another misunderstanding: When I set the sample rate to 0, it seems that only the child span is displayed in the LIVE view: …whereas when I set it to 100, I see both child & parent, in the LIVE view and also in the indexed view: Is this expected behaviour? |
Hello @shagedorn 👋 That is unexpected. I can easily replicate and I can confirm that the SDK is sending both span events when sampled out. Thank you for the report! |
Hello 👋 So I have more insights from the APM intake team: as @ncreated explained, the Live view presents events between ingestion and indexing. The sample decision for keeping a trace is based on the root span (the Here a more detailed description of the Ingestion flow: https://docs.datadoghq.com/tracing/trace_pipeline/ingestion_controls/ So this behaviour is by-design of our ingestion flow and the LIVE view. I hope it's clear, let me know if you need more info! |
Thanks a lot for digging into this and providing additional details! I will close this issue then, it seems that there's no bug, just a misinterpretation. |
Describe the bug
In our app, we have automatic network tracking/tracing enabled, but also send a few custom traces. We apply the trace sample rate in several places in the Datadog setup (shortened for brevity):
We noticed in production that some of our custom traces show up much more often than others and suspected an issue with the sampling rate.
Reproduction steps
We were able to track it down by setting the sample rate to 0 (in our debug environment), and could see that a few traces always come through regardless. It turns out all custom traces with a parent trace are affected, regardless if we set the parent explicitly or Datadog detects it automatically. So, in pseudocode:
…would lead to
trace2
escaping the downsampling.…whereas this works as expected – given a sample rate of 0, neither of them would be sent.
SDK logs
Expected behavior
The trace sample rate should govern all traces to effectively limit cost.
We will need to disable custom traces entirely until this is fixed because it produces costs we cannot control, so we hope for a quick solution.
Affected SDK versions
2.14.2 - 2.17.0
Latest working SDK version
unknown
Did you confirm if the latest SDK version fixes the bug?
Yes
Integration Methods
SPM
Xcode Version
Xcode 15.4
Swift Version
Swift 5.9
MacOS Version
macOS Sonoma 14.7 (23H124)
Deployment Target
iOS 16
Device Information
Reproduces in simulators and devices
Other relevant information
No response
The text was updated successfully, but these errors were encountered: