Skip to content

feat(sampling): Support for OpenTelemetry consistent tracestate sampling - #12397

Open
MilanGarnier wants to merge 12 commits into
masterfrom
milan.garnier/ot.th
Open

MilanGarnier wants to merge 12 commits into
masterfrom
milan.garnier/ot.th

Conversation

@MilanGarnier

@MilanGarnier MilanGarnier commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Adds OpenTelemetry consistent probability-sampling behavior on top of the
ot tracestate parsing introduced by #12405.

  • Validates and normalizes rv and th.
  • Generates probability state for loaded agent rates and sampling rules.
  • Preserves inherited randomness and unknown fields across overrides.
  • Keeps limiter outcomes distinct from raw probability decisions.
  • Adds focused parsing, propagation, continuation, and sampling tests.

Motivation

Make Java tracer sampling decisions interoperable with OpenTelemetry
consistent probability sampling and provide the state needed for downstream
tracestate propagation.

Additional Notes

Contributor Checklist

  • Format the title according to the contribution guidelines.
  • Assign the required type: and comp: labels.

Jira ticket: APMAPI-2171

@MilanGarnier MilanGarnier added type: feature Enhancements and improvements comp: context propagation Trace context propagation tag: ai generated Largely based on code generated by an AI or LLM labels Sep 3, 2026
@MilanGarnier MilanGarnier changed the title Support OpenTelemetry tracestate sampling feat(sampling): Support for OpenTelemetry consistent tracestate sampling Sep 3, 2026
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 54.75% (-4.30%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ac097ca | Docs | View more details | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.90 s 14.68 s [+0.5%; +2.5%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.60 s 13.74 s [-2.0%; -0.1%] (maybe better)
startup:petclinic:appsec:Agent 17.49 s 17.41 s [-0.6%; +1.5%] (no difference)
startup:petclinic:iast:Agent 17.39 s 17.50 s [-1.3%; +0.2%] (no difference)
startup:petclinic:profiling:Agent 17.23 s 17.25 s [-1.4%; +1.0%] (no difference)
startup:petclinic:sca:Agent 16.84 s 17.30 s [-6.9%; +1.6%] (no difference)
startup:petclinic:tracing:Agent 16.58 s 16.65 s [-1.3%; +0.4%] (no difference)

Commit: ac097ca2 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@MilanGarnier
MilanGarnier changed the base branch from master to milan.garnier/preserve-deterministic-sampler-rate September 3, 2026 13:59
Base automatically changed from milan.garnier/preserve-deterministic-sampler-rate to master September 3, 2026 18:45
@MilanGarnier
MilanGarnier changed the base branch from master to milan.garnier/otel-tracestate-refactor September 4, 2026 09:30
@MilanGarnier
MilanGarnier force-pushed the milan.garnier/ot.th branch 5 times, most recently from 7a1ddea to a0176c9 Compare September 8, 2026 14:26
@MilanGarnier

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread dd-trace-core/src/main/java/datadog/trace/core/DDSpanContext.java Outdated
@MilanGarnier
MilanGarnier marked this pull request as ready for review September 10, 2026 09:02
@MilanGarnier
MilanGarnier requested review from a team as code owners September 10, 2026 09:02
@MilanGarnier
MilanGarnier requested review from mhlidd and removed request for a team September 10, 2026 09:02
@MilanGarnier
MilanGarnier force-pushed the milan.garnier/otel-tracestate-refactor branch from db321c0 to 1c02400 Compare September 10, 2026 09:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread dd-trace-core/src/main/java/datadog/trace/core/propagation/HttpCodec.java Outdated
Comment thread dd-trace-core/src/main/java/datadog/trace/core/DDSpan.java Outdated

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: FAIL

Compound extraction can emit a W3C sampled flag that conflicts with the propagated OTel probability threshold when propagation styles have different sampling decisions.

Open Bits AI session

🤖 Datadog Autotest · Commit 3c81345 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@MilanGarnier
MilanGarnier removed this pull request from stack #12406 September 14, 2026 13:01
Base automatically changed from milan.garnier/otel-tracestate-refactor to master September 14, 2026 14:41
@MilanGarnier
MilanGarnier added this pull request to stack #12487 September 14, 2026 16:17
@MilanGarnier

Copy link
Copy Markdown
Contributor Author

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.

@MilanGarnier

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@MilanGarnier
MilanGarnier marked this pull request as ready for review September 15, 2026 09:47
@MilanGarnier
MilanGarnier removed this pull request from stack #12487 September 15, 2026 09:47

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: FAIL

A matching traceparent and Datadog priority can keep an OTel threshold that gives the opposite sampling decision. Reinjection then sends conflicting sampling data.

Open Bits AI session

🤖 Datadog Autotest · Commit d324e16 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

Comment on lines +790 to +795
SamplingState currentState = samplingState;
this.samplingState =
newSamplingState(
currentState.getSamplingPriority(),
tracestate,
otelTraceState,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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 traceparent with tracestate: 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 sampled traceparent with an ot state that means drop.
Suggested change
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

@mcculls
mcculls self-requested a review September 15, 2026 10:28
@MilanGarnier
MilanGarnier requested a review from a team as a code owner September 15, 2026 12:23
@MilanGarnier
MilanGarnier requested review from vandonr and removed request for a team September 15, 2026 12:23

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: FAIL

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.

Open Bits AI session

🤖 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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: context propagation Trace context propagation tag: ai generated Largely based on code generated by an AI or LLM type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants