Repository navigation
Description
Description:
Problem
Since #45830 (Envoy 1.39), the OpenTelemetry tracer applies Envoy's tracing decision as a final veto, even when a valid parent span context was extracted:
envoy/source/extensions/tracers/opentelemetry/opentelemetry_tracer_impl.cc
Lines 273 to 294 in baf651b
| auto applyTracingDecision = [&tracing_decision](Tracing::SpanPtr span) -> Tracing::SpanPtr { | |
| if (!tracing_decision.traced) { | |
| span->setSampled(false); | |
| } | |
| return span; | |
| }; | |
| // The first format with a valid span context becomes the parent. Malformed formats are skipped. | |
| bool malformed_trace_context = false; | |
| for (const TraceContextFormat format : incoming_trace_context_) { | |
| std::optional<absl::StatusOr<SpanContext>> span_context = | |
| extractSpanContext(format, trace_context, tracing_decision.traced); | |
| if (!span_context.has_value()) { | |
| continue; | |
| } | |
| if (!span_context->ok()) { | |
| ENVOY_LOG(debug, "Unable to extract span context: {}", span_context->status()); | |
| malformed_trace_context = true; | |
| continue; | |
| } | |
| return applyTracingDecision(tracer.startSpan(operation_name, stream_info, | |
| stream_info.startTime(), span_context->value(), | |
| trace_context, span_kind)); |
With random_sampling below 100%, a request that arrives with traceparent: ...-01 is therefore sampled only at the random_sampling rate. Most of the time the downstream service has already decided to sample the trace, and Envoy drops it.
The span's sampled flag is also what Envoy injects into the outgoing traceparent (tracer.cc#L126). So when Envoy vetoes a request, the services behind it also see an unsampled parent, and with the usual parent-based samplers the rest of the trace is dropped too.
This affects Istio directly. Istio maps Telemetry.tracing.randomSamplingPercentage to HCM random_sampling and documents that "if a prior sampling decision has been made, that decision will be respected". See istio/istio#62440. One user also reported trace loss in production after upgrading (kyma-project/telemetry-manager#3907).
Reproduction
The setup is a single Envoy with random_sampling: 10, the OpenTelemetry tracer exporting over HTTP to a local sink, and default client_sampling / overall_sampling (100%). 300 requests per case, counting tracing.opentelemetry.spans_sent:
| Envoy | no trace header | traceparent ...-01 |
traceparent ...-00 |
x-client-trace-id |
|---|---|---|---|---|
| 1.38.9 | 29 | 300 | 0 | 300 |
| 1.39.6 | 29 | 32 | 0 | 300 |
| 1.40.2 | 28 | 34 | 0 | 300 |
| dev (1.41.0-dev) | 32 | 26 | 0 | 300 |
The config and script are available, and I can attach them here.
Why the tracer cannot tell these cases apart today
The HCM reports Reason::NotTraceable for several different situations (conn_manager_utility.cc#L394-L451):
- The request was not selected by
random_sampling. Envoy made no decision against tracing it. - The request was selected, then rejected by
overall_sampling. - The request carried
x-client-trace-idbut was rejected byclient_sampling(and not selected by random sampling). This is the opentelemetry tracing provider doesn't respect client_sampling when both traceparent and x-client-trace-id header is present #35721 case. - The request ID is missing or invalid, so no sampling decision was computed.
Only case 1 is "no decision". The other cases are explicit rejections, or have no basis for honoring the parent, and #45830 rightly keeps vetoing them. Overall sampling is also currently not evaluated at all in case 1.
Proposal
An opt-in change that keeps the current default behavior:
- HCM: add
bool parent_sampling_allowed{false}toTracing::Decision. The HCM sets it totrueonly when the request (withoutx-client-trace-id) was not selected by random sampling and passesoverall_sampling. To make this possible, overall sampling is also evaluated in that case. All other paths, including early returns for a missing or invalid request ID, leave itfalse. - OpenTelemetry tracer: add
bool honor_parent_sampling_decision = 13;toOpenTelemetryConfig(defaultfalse). When it istrue, a valid parent context is present,reason == NotTraceableandparent_sampling_allowedistrue, the span keeps the parent's decision (or the configured sampler's decision) instead of being vetoed.
Unchanged:
- The default behavior, so the tracing: make otel tracer respect envoy tracing decision #45830 / opentelemetry tracing provider doesn't respect client_sampling when both traceparent and x-client-trace-id header is present #35721 semantics stay as they are.
overall_samplingrejections,client_samplingrejections ofx-client-trace-id, missing or invalid request IDs, and health checks still veto.- Root spans (no parent context).
- As today for spans that follow their parent, a later route refresh does not change the decision.
With this in place, Istio would set honor_parent_sampling_decision: true.
Alternatives considered
- Change the default behavior, with a runtime guard: this fixes Istio without any config change, but it changes the behavior tracing: make otel tracer respect envoy tracing decision #45830 intentionally introduced. I am happy to go this way if maintainers prefer it; the HCM part is the same.
use_request_id_for_trace_sampling: false: the parent flag is respected, but every request without a parent is also sampled (300/300 in the repro above), so the sampling rate is lost.parent_based(trace_id_ratio_based)sampler withrandom_sampling: 100: the parent flag is respected, butx-client-trace-idno longer forces sampling (27/300).- Sending
x-client-trace-idalong withtraceparent ...-01: this works today, but it needs changes in every client and requiresx-request-idto be propagated across hops. It is a workaround, not a fix.
Questions
- Is opt-in the preferred direction, or would you rather change the default behind a runtime guard?
- Is extending
Tracing::Decisionacceptable for carrying this signal from the HCM to tracers?
I have a patch with unit tests (HCM and OpenTelemetry tracer) and an end-to-end repro, and will open a PR referencing this issue.
Relevant Links:
- tracing: make otel tracer respect envoy tracing decision #45830 (change that introduced the veto), opentelemetry tracing provider doesn't respect client_sampling when both traceparent and x-client-trace-id header is present #35721 (the issue it fixed)
- randomSamplingPercentage overrides traceparent sampled flag (flags=01) since Envoy 1.39 istio/istio#62440
- test: add integration tests for Istio traceparent sampling behaviour kyma-project/telemetry-manager#3907
- W3C Trace Context, sampled flag: https://www.w3.org/TR/trace-context/#sampled-flag
Activity
tracing: add option to honor parent sampling decision in opentelemetr…
tracing: add option to honor parent sampling decision in opentelemetr…
tracing: add option to honor parent sampling decision in opentelemetr…
tracing: add option to honor parent sampling decision in opentelemetr…
tracing: add option to honor parent sampling decision in opentelemetr…
tracing: honor sampled parent when local sampling misses
eottabom commentedon Dec 1, 2026
Hi @yanavlasov @mattklein123, could you take a look at this proposal when you have a chance?
Sendbird has also encountered the same issue and is working on a similar implementation in sendbird#31.
I’ve prepared a reference implementation that preserves the existing behavior by default and respects explicit sampling vetoes.
I’d appreciate your feedback on the proposed approach before opening an upstream PR.
Thanks!