opentelemetry-rust icon indicating copy to clipboard operation
opentelemetry-rust copied to clipboard

[Feature]: Add export_unsampled option to BatchSpanProcessor (opt-in export of recording but unsampled spans)

Open agent-adam opened this issue 3 months ago • 1 comments

Related Problems?

By default, the Rust SDK exports only sampled spans. There is no way to export recording but unsampled spans. This makes it difficult to:

  • Generate accurate span-to-metrics pipelines (RED metrics, error ratios, SLO burn).
  • Feed tail-samplers in a Collector with complete input, while still limiting upstream egress.

Other SDKs have moved forward with this support:

Currently, the Rust SDK even fixed a bug to stop exporting unsampled spans (#871), so there is no supported opt-in path today.

Describe the solution you'd like:

I’d like the API to expose an opt-in flag on BatchSpanProcessor (and plumb it through to exporters) that enables exporting recording-but-unsampled spans.

Example sketch:

let exporter = opentelemetry_otlp::new_exporter().tonic().with_endpoint("http://localhost:4317");
let bsp = BatchSpanProcessor::builder(exporter, runtime)
    .with_export_unsampled(true) // <-- new opt-in
    .build();

Expected behavior:

  • Default remains false (only sampled spans exported).
  • When true, spans with is_recording == true but TraceFlags::SAMPLED == false are also exported.
  • Exporters may mark these as unsampled so downstream can distinguish them.

Considered Alternatives

No response

Additional Context

No response

Tip

React with šŸ‘ to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

agent-adam avatar Aug 27 '25 21:08 agent-adam

This is a gap in the OpenTelemetry specification.

https://github.com/open-telemetry/opentelemetry-specification/issues/2986

I support specification work on this, especially if it will help solve the issue here.

jmacd avatar Oct 09 '25 15:10 jmacd