Skip to content

Add opt-in to export *unsampled but recording* Activities from trace processors #3610

@agent-adam

Description

@agent-adam

Before opening a feature request against this repo, consider whether the feature should/could be implemented in the other OpenTelemetry client libraries. If so, please open an issue on opentelemetry-specification first.


Is your feature request related to a problem?
Yes. By default, the C++ SDK only exports sampled spans. This prevents collectors from seeing the full request volume, which makes it difficult to calculate accurate metrics (e.g., request rates, error ratios, latency percentiles) or perform tail-based sampling decisions with complete coverage.

In the Java SDK, this problem was tracked in:

  • Issue #4990 — Proposal to forward non-sampled spans to SpanProcessors/Exporters
  • PR #6057 — Merged implementation adding an exportUnsampledSpans option

C++ processors (BatchSpanProcessor, SimpleSpanProcessor) currently drop unsampled spans unconditionally, leaving no opt-in for users who want to forward them.


Describe the solution you'd like
Introduce an opt-in flag on the span processors (e.g., BatchSpanProcessorOptions, SimpleSpanProcessorOptions) that allows unsampled-but-recording spans to be forwarded to exporters.

Example pseudocode:

// sdk/include/opentelemetry/sdk/trace/batch_span_processor_options.h
struct BatchSpanProcessorOptions {
  // Existing fields...
  bool export_unsampled_spans = false; // default false
};

// sdk/src/trace/batch_span_processor.cc (simplified pseudocode)
void BatchSpanProcessor::OnEnd(std::unique_ptr<Recordable> &&span) noexcept {
  auto *readable = static_cast<ReadableSpan*>(span.get());
  bool is_sampled = readable->GetSpanContext().IsSampled();

  if (!is_sampled && !options_.export_unsampled_spans) {
    return;
  }

  this->queue_.Add(std::move(span));
}

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.

Metadata

Metadata

Assignees

Labels

needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions