dstandish opened a new pull request, #68591:
URL: https://github.com/apache/airflow/pull/68591

   ## Problem
   
   DAG-run traces hang off `dag_run.context_carrier` (a W3C traceparent), and 
`new_dagrun_trace_carrier()` hardcoded `TraceFlags.SAMPLED`. Since that flag is 
the parent for every downstream span (`dag_run`, `task_run`, worker), 
hardcoding it defeats the configured sampler: `OTEL_TRACES_SAMPLER` / 
`OTEL_TRACES_SAMPLER_ARG` are read by the SDK but control nothing for these 
spans — every run is always sampled.
   
   ## Change
   
   Make the carrier carry an honest sampling decision from the configured 
sampler instead of a hardcoded flag:
   
   - `new_dagrun_trace_carrier()` consults the tracer provider's sampler for a 
root decision and sets the SAMPLED flag accordingly. When there is no real 
provider (tracing disabled) it falls back to not-sampled — observably identical 
to today, since nothing exports.
   - `_emit_dagrun_span` honors the flag. This is **required**: it forces a 
root span (`context=context.Context()`), so the sampler would otherwise never 
see the carrier's flag.
   - `_emit_task_span` honors the flag too — a parent-based sampler would 
already drop the child, but the explicit check also covers non-parent-based 
samplers and short-circuits before building the span.
   - Worker / detail spans already inherit the decision via `ParentBased`.
   
   ## Behavior
   
   | `OTEL_TRACES_SAMPLER` | Result |
   |---|---|
   | *(unset)* | `parentbased_always_on` → everything traced (**unchanged / 
backcompat**) |
   | `always_on` | everything traced |
   | `traceidratio` + arg `0.05` | ~5% head-sampled, deterministic per trace_id 
|
   | `always_off` | nothing |
   | tracing disabled | nothing exports (unchanged) |
   
   Backcompat is automatic: the SDK default `parentbased_always_on` samples 
every root decision, so anyone who hasn't set the env var sees no change.
   
   ## Tests
   
   Added coverage for the sampler-driven flag (always_on/off, ratio 
determinism, no-provider fallback), the emit-time guards (emit when sampled, 
skip when head-sampled out, still emit for empty/legacy carriers), and 
detail-level tracestate round-tripping.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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]

Reply via email to