Class FilteringSpanExporter

java.lang.Object
io.opentelemetry.contrib.filter.FilteringSpanExporter
All Implemented Interfaces:
io.opentelemetry.sdk.trace.export.SpanExporter, Closeable, AutoCloseable

public final class FilteringSpanExporter extends Object implements io.opentelemetry.sdk.trace.export.SpanExporter
A SpanExporter wrapper that filters spans before delegating to the underlying exporter. Filtering operates at the trace level within each export batch: if any filter matches, all spans sharing that trace ID in that batch are exported together.

Two types of filters are supported:

  • SpanFilter - evaluates individual spans (e.g., error status, slow duration)
  • TraceFilter - evaluates all spans belonging to a trace within the batch (e.g., overall trace wall-clock duration)

A trace's spans are kept if any SpanFilter matches any span in the batch, OR any TraceFilter matches the trace's span group within the batch.

Important: Filtering decisions are scoped to a single export(Collection) call. Spans from the same trace that arrive in different batches are evaluated independently, so a trace split across batches may be partially exported.

  • Constructor Summary

    Constructors
    Constructor
    Description
    FilteringSpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter delegate, List<SpanFilter> spanFilters, List<TraceFilter> traceFilters)
    Creates a new FilteringSpanExporter without metrics.
    FilteringSpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter delegate, List<SpanFilter> spanFilters, List<TraceFilter> traceFilters, io.opentelemetry.api.metrics.Meter meter)
    Creates a new FilteringSpanExporter.
  • Method Summary

    Modifier and Type
    Method
    Description
    io.opentelemetry.sdk.common.CompletableResultCode
    export(Collection<io.opentelemetry.sdk.trace.data.SpanData> spans)
     
    io.opentelemetry.sdk.common.CompletableResultCode
     
    io.opentelemetry.sdk.common.CompletableResultCode
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.opentelemetry.sdk.trace.export.SpanExporter

    close
  • Constructor Details

    • FilteringSpanExporter

      public FilteringSpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter delegate, List<SpanFilter> spanFilters, List<TraceFilter> traceFilters, @Nullable io.opentelemetry.api.metrics.Meter meter)
      Creates a new FilteringSpanExporter.
      Parameters:
      delegate - the exporter to delegate to for spans that pass filtering
      spanFilters - per-span filters; a trace's spans in the batch are kept if any filter matches
      traceFilters - batch-level filters; a trace's spans in the batch are kept if any filter matches
      meter - optional Meter for emitting dropped-span metrics; pass null to disable metrics
    • FilteringSpanExporter

      public FilteringSpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter delegate, List<SpanFilter> spanFilters, List<TraceFilter> traceFilters)
      Creates a new FilteringSpanExporter without metrics.
      Parameters:
      delegate - the exporter to delegate to for spans that pass filtering
      spanFilters - per-span filters
      traceFilters - batch-level filters
  • Method Details

    • export

      public io.opentelemetry.sdk.common.CompletableResultCode export(Collection<io.opentelemetry.sdk.trace.data.SpanData> spans)
      Specified by:
      export in interface io.opentelemetry.sdk.trace.export.SpanExporter
    • flush

      public io.opentelemetry.sdk.common.CompletableResultCode flush()
      Specified by:
      flush in interface io.opentelemetry.sdk.trace.export.SpanExporter
    • shutdown

      public io.opentelemetry.sdk.common.CompletableResultCode shutdown()
      Specified by:
      shutdown in interface io.opentelemetry.sdk.trace.export.SpanExporter