← Back to Pull requests

fix(tracing): fall back to remaining styles in extract-first mode #22221

Open
unknown opened this pull request with 395 lines diff across 4 files
View on GitHub
unknown unknown commented on Dec 01, 2026 12:03 UTC
Author

Description

Fixes DD_TRACE_PROPAGATION_EXTRACT_FIRST=true in ddtrace/propagation/http.py so HTTP trace context extraction continues checking configured propagation styles in order until one matches, instead of stopping after the first configured style on a miss and returning None.

Minimal reproducer

from ddtrace.internal.settings._config import config
from ddtrace.propagation.http import HTTPPropagator

config._propagation_style_extract = ["datadog", "tracecontext"]
config._propagation_extract_first = True      # DD_TRACE_PROPAGATION_EXTRACT_FIRST=true

ctx = HTTPPropagator.extract(
    {"traceparent": "00-00000000000000000000000000000001-0000000000000002-01"}
)
print(ctx)   # None   (expected: Context(trace_id=1, span_id=2))

Root causes and changes

1. Break only on match: Moved break, telemetry recording, and legacy ot-baggage- attachment inside if extracted_context: so a missing or malformed first style falls through to remaining configured styles (tracecontext, b3multi, b3).
2. Preserve empty Context() on miss: Extract into a temporary extracted_context before assigning to context so HTTPPropagator.extract() returns an empty Context() rather than None when no style matches.
3. Skip "baggage" inside the trace loop: Matched the default multi-style path by skipping _PROPAGATION_STYLE_BAGGAGE inside the extract-first loop so W3C baggage stays handled independently afterward (avoiding early exit or duplicate baggage telemetry when "baggage" precedes a trace style).

Customer impact

Customers enabling DD_TRACE_PROPAGATION_EXTRACT_FIRST=true with multiple propagation styles (including the default datadog,tracecontext,baggage) now preserve distributed traces carried in fallback styles and receive an empty Context() instead of None when no trace headers are present. A fixes release note is included.

Testing

Local validation only (not yet run in CI):

  • Confirmed 12 of 16 new regression tests fail on origin/main before the fix.

  • scripts/run-tests -r --venv 4fe876cb327a -- -q -k extract_first (Python 3.12, rebased on main): 17 passed, covering first-style precedence, skipping tracestate merge, fallback to tracecontext/b3multi/b3 and malformed headers, all-styles-miss returning Context(), "baggage" ordering (first/middle/last/only), legacy ot-baggage-, DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT=restart/ignore, and DD_TRACE_PROPAGATION_STYLE_EXTRACT=none.

  • scripts/run-tests --venv 4fe876cb327a -- -q -k test_propagation (Python 3.12): 1,809 passed, 1 xfailed; 8 pre-existing 128-bit subprocess tests failed locally only because no agent listens on localhost:8126 in the local tracer suite.

  • scripts/lint fmt, scripts/lint typing, scripts/lint type-comments-check --base-ref origin/main, and scripts/lint checks: all passed.
  • Risks

    Low. Scoped strictly to the config._propagation_extract_first branch in HTTPPropagator.extract; the default (False) extraction path is unchanged.

    Additional Notes

    Release note: releasenotes/notes/fix-propagation-extract-first-8c51d7cda3330f40.yaml.

    Diff: 395 lines (+296 / -99) across 4 files Reviewer: gnufede Review duration: 257m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 395 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.358
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #22221"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.2% (MEDIUM) · Higher = larger blast radius
    43.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23% · Safe to merge
    23%