Skip to content

feat: OTel process and thread contexts#4062

Open
morrisonlevi wants to merge 7 commits into
masterfrom
PROF-15487-Implement-OTel-process-and-thread-context-dd-trace-php
Open

feat: OTel process and thread contexts#4062
morrisonlevi wants to merge 7 commits into
masterfrom
PROF-15487-Implement-OTel-process-and-thread-context-dd-trace-php

Conversation

@morrisonlevi

Copy link
Copy Markdown
Collaborator

Description

This implements OTel process and thread contexts described here:

This allows out-of-process readers like an EBPF profiler on Linux to get information from the tracer such as span and trace ids (and more).

This ALSO adds support for W3C trace flags in more places. This part needs specific review too, but I added it because it's part of these OTEPs to use it.

Platforms

To avoid having significantly different APIs on Linux vs macOS/Windows, this PR implements process and thread contexts on macOS and Windows too. They lack discovery and out-of-process readers: it's just and internal detail and is non-standard. There are still some divergences to make this work (they use different thread local storage mechanisms) but at the high level they are quite similar.

The profiler has been ported to use process and thread contexts when available on all platforms.

Notes

I need help to implement and verify the Windows portion.

Since PHP can have different service, env, version, etc on every request, we do not store these as resource attributes in the process context. Instead they are stored as thread attributes. I've opened a draft PR for our EBPF profiler fork to understand this pattern, and I've verified locally that it works.

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

@morrisonlevi
morrisonlevi requested review from a team as code owners July 24, 2026 15:23
@morrisonlevi
morrisonlevi requested review from sameerank and vjfridge and removed request for a team July 24, 2026 15:23
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 24, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

🚦 205 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-php | appsec integration tests: [test8.4-release]   View in Datadog   GitLab

🧪 1 Test failed

All test failures are known flaky.

❄️ Known flaky: extended heartbeat re-emits configuration, dependencies and integrations() from com.datadog.appsec.php.integration.TelemetryExtendedHeartbeatTests   View in Datadog
java.lang.AssertionError: phpredis not emitted via app-started/app-integrations-change; saw: []. Expression: (phpredis in flushed). Values: flushed = []

java.lang.AssertionError: phpredis not emitted via app-started/app-integrations-change; saw: []. Expression: (phpredis in flushed). Values: flushed = []
	at org.codehaus.groovy.runtime.InvokerHelper.createAssertError(InvokerHelper.java:416)
	at com.datadog.appsec.php.integration.TelemetryExtendedHeartbeatTests.extended heartbeat re-emits configuration, dependencies and integrations(TelemetryExtendedHeartbeatTests.groovy:70)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Not introduced in this PR.

DataDog/apm-reliability/dd-trace-php | Cargo test   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-php | PHP language tests: [7.1, amd64, nts]   View in Datadog   GitLab

View all 205 failed jobs.

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 0.00%
Overall Coverage: 60.64% (-0.01%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6d8c87e | Docs | Datadog PR Page | Give us feedback!

@pr-commenter

pr-commenter Bot commented Jul 24, 2026

Copy link
Copy Markdown

Benchmarks [ tracer ]

Benchmark execution time: 2026-07-24 16:41:23

Comparing candidate commit 6d8c87e in PR branch PROF-15487-Implement-OTel-process-and-thread-context-dd-trace-php with baseline commit f068c9e in branch master.

Found 9 performance improvements and 8 performance regressions! Performance is the same for 177 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:ContextPropagationBench/benchInject64Bit-opcache

  • 🟩 execution_time [-11.265µs; -11.083µs] or [-83.701%; -82.344%]

scenario:SamplingRuleMatchingBench/benchRegexMatching1

  • 🟥 execution_time [+60.167ns; +165.233ns] or [+4.054%; +11.134%]

scenario:SamplingRuleMatchingBench/benchRegexMatching2

  • 🟥 execution_time [+69.588ns; +138.012ns] or [+4.748%; +9.417%]

scenario:SamplingRuleMatchingBench/benchRegexMatching3

  • 🟥 execution_time [+64.176ns; +127.824ns] or [+4.303%; +8.571%]

scenario:SamplingRuleMatchingBench/benchRegexMatching4

  • 🟥 execution_time [+54.004ns; +112.996ns] or [+3.622%; +7.579%]

scenario:SpanBench/benchDatadogAPI

  • 🟥 execution_time [+2.572µs; +5.178µs] or [+3.830%; +7.711%]

scenario:SpanBench/benchDatadogAPI-opcache

  • 🟥 execution_time [+1.572µs; +2.969µs] or [+2.342%; +4.424%]

scenario:SpanBench/benchOpenTelemetryAPI

  • 🟩 execution_time [-350.020µs; -341.986µs] or [-49.743%; -48.601%]
  • 🟩 mem_peak [-6.850MB; -6.850MB] or [-14.364%; -14.364%]

scenario:SpanBench/benchOpenTelemetryAPI-opcache

  • 🟩 execution_time [-327.743µs; -322.093µs] or [-50.551%; -49.679%]
  • 🟩 mem_peak [-6.829MB; -6.829MB] or [-15.272%; -15.271%]

scenario:SpanBench/benchOpenTelemetryInteroperability

  • 🟥 mem_peak [+643.603KB; +643.613KB] or [+2.232%; +2.232%]

scenario:SpanBench/benchOpenTelemetryInteroperability-opcache

  • 🟥 mem_peak [+641.573KB; +641.581KB] or [+2.478%; +2.478%]

scenario:TraceFlushBench/benchFlushTrace

  • 🟩 execution_time [-935.862µs; -924.238µs] or [-73.789%; -72.872%]

scenario:TraceFlushBench/benchFlushTrace-opcache

  • 🟩 execution_time [-913.093µs; -876.607µs] or [-38.218%; -36.691%]

scenario:TraceSerializationBench/benchSerializeTrace

  • 🟩 execution_time [-46.253µs; -32.947µs] or [-9.834%; -7.005%]

scenario:TraceSerializationBench/benchSerializeTrace-opcache

  • 🟩 execution_time [-46.243µs; -34.057µs] or [-11.258%; -8.291%]

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.

1 participant