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

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

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

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.

agent-adam avatar Aug 25 '25 23:08 agent-adam

@trask - this issue works with copilot.

lalitb avatar Aug 28 '25 22:08 lalitb

To discuss, file a spec PR to have a common expected behavior, naming parameters, etc, for all repos.

marcalff avatar Sep 08 '25 20:09 marcalff

This issue was marked as stale due to lack of activity.

github-actions[bot] avatar Nov 08 '25 02:11 github-actions[bot]