Skip to content

opentelemetry: option to honor a sampled parent context when a request is only not selected by random_sampling #49638

Backlog

Description

@eottabom

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:

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):

  1. The request was not selected by random_sampling. Envoy made no decision against tracing it.
  2. The request was selected, then rejected by overall_sampling.
  3. The request carried x-client-trace-id but was rejected by client_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.
  4. 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:

  1. HCM: add bool parent_sampling_allowed{false} to Tracing::Decision. The HCM sets it to true only when the request (without x-client-trace-id) was not selected by random sampling and passes overall_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 it false.
  2. OpenTelemetry tracer: add bool honor_parent_sampling_decision = 13; to OpenTelemetryConfig (default false). When it is true, a valid parent context is present, reason == NotTraceable and parent_sampling_allowed is true, the span keeps the parent's decision (or the configured sampler's decision) instead of being vetoed.

Unchanged:

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 with random_sampling: 100: the parent flag is respected, but x-client-trace-id no longer forces sampling (27/300).
  • Sending x-client-trace-id along with traceparent ...-01: this works today, but it needs changes in every client and requires x-request-id to 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::Decision acceptable 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:

Activity

  1. added 6 commits that reference this issue on Nov 26, 2026
    4445158
    a302e74
    ea7ca81
    0eda4f5
    e85f864
    0d2af4b
  2. eottabom commented on Dec 1, 2026

    @eottabom
    Author

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions