Class SamplingTraceExporter

  • All Implemented Interfaces:
    io.opentelemetry.sdk.trace.export.SpanExporter , java.io.Closeable , java.lang.AutoCloseable

    
    public final class SamplingTraceExporter
     implements SpanExporter
                        

    A SpanExporter that applies sampling logic before delegating to an OtlpHttpLogRecordExporter.

    This exporter wraps an OtlpHttpSpanExporter and uses a ExportSampler to determine which spans should be exported based on configurable sampling rules. Spans that don't match the sampling criteria are filtered out, reducing the volume of telemetry data sent to the observability backend.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      CompletableResultCode export(Collection<SpanData> spans) Exports spans after applying sampling logic.
      CompletableResultCode flush() Flushes any pending spans in the underlying exporter.
      CompletableResultCode shutdown() Shuts down the exporter and releases any resources.
      • Methods inherited from class io.opentelemetry.sdk.trace.export.SpanExporter

        close
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SamplingTraceExporter

        SamplingTraceExporter(OtlpHttpSpanExporter delegate, ExportSampler sampler)
        Parameters:
        delegate - The underlying OtlpHttpSpanExporter that handles the actual export
        sampler - The custom sampler that determines which spans to export
    • Method Detail

      • export

         CompletableResultCode export(Collection<SpanData> spans)

        Exports spans after applying sampling logic.

        This method filters the provided spans using the configured sampler, then delegates the export of sampled spans to the underlying OTLP exporter. If no spans pass the sampling criteria, the export is considered successful without sending any data.

        Parameters:
        spans - The collection of spans to potentially export
        Returns:

        A CompletableResultCode indicating the success or failure of the export operation

      • flush

         CompletableResultCode flush()

        Flushes any pending spans in the underlying exporter.

        Returns:

        A CompletableResultCode indicating the success or failure of the flush operation

      • shutdown

         CompletableResultCode shutdown()

        Shuts down the exporter and releases any resources.

        Returns:

        A CompletableResultCode indicating the success or failure of the shutdown operation