dstandish commented on code in PR #69633:
URL: https://github.com/apache/airflow/pull/69633#discussion_r3573912902
##########
airflow-core/newsfragments/69633.feature.rst:
##########
Review Comment:
done
##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -194,6 +195,33 @@ def trace_sampled_override(conf) -> bool | None:
return None
+def parent_trace_context(conf) -> context.Context | None:
+ """
+ External parent trace context from the
``airflow/dagrun_parent_trace_context`` run conf key.
+
+ Lets a run be embedded in a trace owned by an external system (an upstream
+ orchestrator, event pipeline, CI job, another Airflow) instead of being a
root
+ trace. The value is a W3C ``traceparent`` string, or a carrier dict
carrying
+ ``traceparent`` (and optionally ``tracestate``); anything else --
including a
+ malformed traceparent -- is ignored so it can neither silently mis-parent
the
+ run nor fail run creation. Returns an OpenTelemetry ``Context`` when a
valid
+ parent is present, else None (root trace, the default).
+ """
+ if not conf:
+ return None
+ raw = conf.get(DAGRUN_PARENT_TRACE_CONTEXT_KEY)
+ if isinstance(raw, str):
+ carrier = {"traceparent": raw}
+ elif isinstance(raw, dict) and isinstance(raw.get("traceparent"), str):
+ carrier = {k: raw[k] for k in ("traceparent", "tracestate") if
isinstance(raw.get(k), str)}
Review Comment:
Kept it string-only for now. `tracestate` is a W3C header string —
comma-separated, ordered members (leftmost = most recently mutated), 32-member
cap — and in practice it's forwarded verbatim from an upstream carrier rather
than hand-authored, so both `traceparent` and `tracestate` already arrive as
strings. Passing the string straight to
`TraceContextTextMapPropagator().extract()` lets OTel own all the member
validation and ordering; accepting a dict would mean we serialize `k=v` and
re-implement those checks ourselves, for a pretty marginal ergonomic win. It's
forward-compatible too — if hand-authoring demand shows up we can add dict
support later without breaking anything.
---
Drafted-by: Claude Code (Opus 4.8); reviewed by @dstandish before posting
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]