feat(sampling): Support for OpenTelemetry consistent tracestate sampling - #12397
MilanGarnier wants to merge 12 commits into
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: ac097ca | Docs | View more details | Give us feedback! |
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
3643548 to
2f90ba6
Compare
a168627 to
9e2422a
Compare
7a1ddea to
a0176c9
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0176c99c0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
db321c0 to
1c02400
Compare
3c81345 to
629892d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 629892d492
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Compound extraction can emit a W3C sampled flag that conflicts with the propagated OTel probability threshold when propagation styles have different sampling decisions.
🤖 Datadog Autotest · Commit 3c81345 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
d5a6721 to
eb4c156
Compare
7772c8c to
cd47a1a
Compare
cd47a1a to
e9d42f7
Compare
|
Since the PR is a bit big (~1100 lines of feature, 1000 of tests), I've rewritten the history into a set of commits that should each be independently reviewable and testable. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9d42f767a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
fdb0a3a to
34ef4a2
Compare
Reuse the immutable empty sampling state across propagation tags. Cache effective W3C tracestate by immutable sampling state identity. Size W3C encoding buffers from the captured sampling state.
34ef4a2 to
d324e16
Compare
There was a problem hiding this comment.
A matching traceparent and Datadog priority can keep an OTel threshold that gives the opposite sampling decision. Reinjection then sends conflicting sampling data.
🤖 Datadog Autotest · Commit d324e16 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
| SamplingState currentState = samplingState; | ||
| this.samplingState = | ||
| newSamplingState( | ||
| currentState.getSamplingPriority(), | ||
| tracestate, | ||
| otelTraceState, |
There was a problem hiding this comment.
Remove a threshold that conflicts with the sampled flag
A downstream OTel sampler can drop a trace that traceparent marks as sampled.
Assertion details
- Input: Use a sampled
traceparentwithtracestate: dd=s:1,ot=rv:00000000000000;th:8. - Expected:
Remove the threshold when the parsed OTel state conflicts with the final sampling priority. - Actual: Extraction keeps
th:8. Injection then sends a sampledtraceparentwith anotstate that means drop.
| SamplingState currentState = samplingState; | |
| this.samplingState = | |
| newSamplingState( | |
| currentState.getSamplingPriority(), | |
| tracestate, | |
| otelTraceState, | |
| SamplingState currentState = samplingState; | |
| int samplingPriority = currentState.getSamplingPriority(); | |
| if (otelTraceState != null | |
| && samplingPriority != PrioritySampling.UNSET | |
| && !otelTraceState.isConsistentWith(samplingPriority > 0)) { | |
| otelTraceState = otelTraceState.withoutThreshold(); | |
| } | |
| this.samplingState = | |
| newSamplingState( | |
| samplingPriority, | |
| tracestate, | |
| otelTraceState, |
Was this helpful? React 👍 or 👎
🤖 Datadog Autotest · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest · Open Bits AI session
There was a problem hiding this comment.
The change can keep an inherited OpenTelemetry threshold that conflicts with a new local sampling decision. It also sends threshold values with extra trailing zeroes.
🤖 Datadog Autotest · Commit a51831b · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
| } | ||
| this.samplingPriority = samplingPriority; | ||
| if (samplingPriority > 0) { | ||
| OtelTraceState nextOtelTraceState = getOtelTraceState(); |
There was a problem hiding this comment.
Keep local decisions consistent with inherited thresholds
A downstream tracer can make a different sampling decision from the decision in the trace flags.
Assertion details
- Input: An inbound ot state contains rv and th. The tracer then makes a local probability decision while the sampling priority permits the update.
- Expected:
The code must use the inherited random value with a threshold that matches the new local decision. It can remove the threshold if it cannot make the values consistent. - Actual:
The code keeps the inherited threshold for most local probability decisions. The inherited threshold can show the opposite decision.
Was this helpful? React 👍 or 👎
🤖 Datadog Autotest · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest · Open Bits AI session
| } | ||
| } else if (startsWith(raw, start, end, THRESHOLD_KEY)) { | ||
| int candidateStart = start + THRESHOLD_KEY.length(); | ||
| if (thresholdStart < 0 && isLowerHex(raw, candidateStart, end, 1, 14)) { |
There was a problem hiding this comment.
Remove trailing zeroes from inherited thresholds
A strict downstream tracer can reject the ot state and stop the consistent sampling decision.
Assertion details
- Input: An inbound ot state contains a valid threshold with extra trailing hexadecimal zeroes, such as th:8000.
- Expected:
The parser must send the standard form th:8 and keep one zero when the threshold is zero. - Actual:
The parser accepts a threshold such as th:8000 and sends the same value again.
Was this helpful? React 👍 or 👎
🤖 Datadog Autotest · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest · Open Bits AI session
duplicate dd and probably more things + regression test
What Does This Do
Adds OpenTelemetry consistent probability-sampling behavior on top of the
ottracestate parsing introduced by #12405.rvandth.Motivation
Make Java tracer sampling decisions interoperable with OpenTelemetry
consistent probability sampling and provide the state needed for downstream
tracestate propagation.
Additional Notes
depends on refactor(propagation): Parse OpenTelemetry tracestate member #12405 which introduced the OtelTracestate class.
system-tests will be enabled in test(java): enable ot.th/ot.rv tracestate sampling scenarios [java@milan.garnier/ot.th] system-tests#7649
OTLP export optimizations (which should already work with this PR, but it can be optimized) will follow in a separate change.
Contributor Checklist
type:andcomp:labels.Jira ticket: APMAPI-2171