Skip to content

feat(tracing): add DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT#3997

Draft
MilanGarnier wants to merge 7 commits into
masterfrom
MilanGarnier/propagation-behavior-extract
Draft

feat(tracing): add DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT#3997
MilanGarnier wants to merge 7 commits into
masterfrom
MilanGarnier/propagation-behavior-extract

Conversation

@MilanGarnier

Copy link
Copy Markdown

Summary

Implements DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT (APMAPI-1941, feature-parity #353) for the PHP tracer, matching behavior already present in .NET, Python, Node, Java, Ruby, and Rust.

Three values:

  • continue (default): inherit upstream trace context unchanged — no behavior change
  • restart: start a fresh trace; the upstream context is captured as a span link with reason=propagation_behavior_extract
  • ignore: drop all extracted context including baggage and sampling priority

Design:

  • Single chokepoint: all extraction funnels through ddtrace_apply_distributed_tracing_result in distributed_tracing_headers.c, covering both request-init and consume_distributed_tracing_headers userland calls
  • restart path: when the root span doesn't yet exist at request-init time, the span link is queued in DDTRACE_G(pending_upstream_span_link) and consumed in ddtrace_open_span when the root span is created
  • Extracted ddtrace_build_span_link_from_result() from SpanLink::fromHeaders for reuse

Test plan

  • tests/ext/distributed_tracing/propagation_behavior_extract_continue.phpt — verifies trace_id inherited, no span link, baggage preserved
  • tests/ext/distributed_tracing/propagation_behavior_extract_restart.phpt — verifies fresh trace_id, span link with correct upstream ids and reason, baggage preserved, _dd.p.* not in link attributes
  • tests/ext/distributed_tracing/propagation_behavior_extract_ignore.phpt — verifies fresh trace_id, no span link, baggage dropped, sampling priority dropped
  • tests/ext/distributed_tracing/propagation_behavior_extract_config.phpt — verifies case-insensitive parsing, invalid value falls back to continue
  • CI phpt suite

Related

  • APMAPI-1941
  • Ruby: dd-trace-rb#5844
  • Rust: dd-trace-rs#248

🤖 Generated with Claude Code

@MilanGarnier MilanGarnier added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label Jun 17, 2026
@datadog-official

datadog-official Bot commented Jun 17, 2026

Copy link
Copy Markdown

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

Profiling ASAN/UBSAN Tests | PHP 8.5 nts-asan (ubuntu-8-core-latest)   View in Datadog   GitHub Actions

❄️ 1 New flaky test detected

tmp/build_extension/tests/ext/distributed_tracing/propagation_behavior_extract_restart.phpt (DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT=restart starts fresh trace with span link) from PHP.tmp.build_extension.tests.ext.distributed_tracing   View in Datadog
008+ 
008- foo_in_tags: no
009+ Fatal error: Uncaught Error: Call to undefined function str_contains() in tmp/build_extension/tests/ext/distributed_tracing/propagation_behavior_extract_restart.php:37
010+ Stack trace:
011+ #0 {main}
012+   thrown in tmp/build_extension/tests/ext/distributed_tracing/propagation_behavior_extract_restart.php on line 37

New test introduced in this PR is flaky.

View in Flaky Test Management

ℹ️ Info

No other issues found (see more)

🧪 All tests passed

Useful? React with 👍 / 👎

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

MilanGarnier and others added 5 commits June 17, 2026 17:11
Adds the new `DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT` config key (values:
continue, restart, ignore) with a CUSTOM(INT) parser, the corresponding
C enum, and the supported-configurations.json entry.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds three behaviors at the single extraction chokepoint
(ddtrace_apply_distributed_tracing_result):

- continue (default): inherit upstream trace context unchanged
- restart: start a fresh trace; upstream captured as a span link with
  reason=propagation_behavior_extract. When the root span doesn't exist
  yet at request-init time, the link is queued in
  DDTRACE_G(pending_upstream_span_link) and attached in ddtrace_open_span.
- ignore: drop all extracted context including baggage and sampling priority

Also extracts ddtrace_build_span_link_from_result() from the SpanLink
fromHeaders method so it can be reused by the restart path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Covers the three behaviors (continue, restart, ignore) and config
parsing (case-insensitive values, invalid value falls back to default).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@MilanGarnier MilanGarnier force-pushed the MilanGarnier/propagation-behavior-extract branch from 6b7e259 to 3ca8428 Compare June 17, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant