Skip to content

feat(tracing): add OpenTelemetry tracestate sampling - #354

Open
MilanGarnier wants to merge 16 commits into
mainfrom
milan.garnier/otel-tracestate-ot-th
Open

feat(tracing): add OpenTelemetry tracestate sampling#354
MilanGarnier wants to merge 16 commits into
mainfrom
milan.garnier/otel-tracestate-ot-th

Conversation

@MilanGarnier

@MilanGarnier MilanGarnier commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds W3C tracestate support for OpenTelemetry ot sampling state.

  • Parses ot separately from Datadog and other vendor state.
  • Retains valid inherited state, drops malformed rv and th values, and writes sampling values for eligible local probability decisions.
  • Carries W3C state only when it belongs to the selected matching trace.

Testing

  • cmake --build .build -j
  • ./.build/test/tests

@pr-commenter

pr-commenter Bot commented Aug 14, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-20 12:29:05

Comparing candidate commit 6eb3ba3 in PR branch milan.garnier/otel-tracestate-ot-th with baseline commit 765983d in branch main.

Found 3 performance improvements and 2 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:BM_HexPadded_uint64/NoPadding

  • 🟥 execution_time [+1.272ns; +1.332ns] or [+2.427%; +2.543%]

scenario:BM_TraceID_HexPadded/NoPadding

  • 🟥 execution_time [+4.020ns; +4.233ns] or [+2.029%; +2.137%]

scenario:BM_TraceID_ParseHex/128bit

  • 🟩 execution_time [-37.427ns; -37.342ns] or [-21.666%; -21.617%]

scenario:BM_TraceID_ParseHex/64bit

  • 🟩 execution_time [-17.590ns; -17.553ns] or [-19.169%; -19.128%]

scenario:BM_TraceTinyCCSource

  • 🟩 execution_time [-2.674ms; -2.396ms] or [-3.456%; -3.096%]

@datadog-datadog-prod-us1

This comment has been minimized.

@MilanGarnier
MilanGarnier force-pushed the milan.garnier/otel-tracestate-ot-th branch 2 times, most recently from 0bbacfe to e6c71eb Compare August 14, 2026 12:42
@MilanGarnier
MilanGarnier force-pushed the milan.garnier/otel-tracestate-ot-th branch from 93fdd98 to cb6e08f Compare August 17, 2026 09:45

@xlamorlette-datadog xlamorlette-datadog left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Mostly nit and opt comments.

Comment thread include/datadog/sampling_decision.h Outdated
Comment thread src/datadog/trace_sampler.cpp Outdated
Comment thread src/datadog/trace_segment.cpp Outdated
Comment thread src/datadog/trace_segment.cpp Outdated
Comment thread src/datadog/trace_segment.cpp Outdated
if (!decision.mechanism || !decision.configured_rate ||
!decision.probability_sampled ||
!is_probability_mechanism(*decision.mechanism) ||
(*decision.probability_sampled && decision.priority <= 0)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: extract this last condition (*decision.probability_sampled && decision.priority <= 0) into a named variable

Comment thread src/datadog/w3c_propagation.cpp Outdated
Comment thread src/datadog/w3c_propagation.cpp Outdated
Comment thread src/datadog/w3c_propagation.cpp Outdated
Comment thread src/datadog/w3c_propagation.cpp Outdated
Comment thread src/datadog/w3c_propagation.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants