# opentelemetry.sdk.trace.export

class opentelemetry.sdk.trace.export.SpanExportResult(*values)

  Bases: `Enum`

  SUCCESS = 0
  FAILURE = 1

class opentelemetry.sdk.trace.export.SpanExporter

  Bases: `object`

  Interface for exporting spans.

  Interface to be implemented by services that want to export spans recorded in their own format.

  To export data this MUST be registered to the :class`opentelemetry.sdk.trace.Tracer` using a `SimpleSpanProcessor` or a `BatchSpanProcessor`.

  export(spans)

    Exports a batch of telemetry data.

    Parameters:

      spans (`Sequence`[`ReadableSpan`]) – The list of `opentelemetry.trace.Span` objects to be exported

    Return type:

      `SpanExportResult`

    Returns:

      The result of the export

  shutdown()

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`

  force_flush(timeout_millis=30000)

    Hint to ensure that the export of any spans the exporter has received prior to the call to ForceFlush SHOULD be completed as soon as possible, preferably before returning from this method.

    Return type:

      `bool`

class opentelemetry.sdk.trace.export.SimpleSpanProcessor(span_exporter, *, meter_provider=None)

  Bases: `SpanProcessor`

  Simple SpanProcessor implementation.

  SimpleSpanProcessor is an implementation of `SpanProcessor` that passes ended spans directly to the configured `SpanExporter`.

  on_start(span, parent_context=None)

    Called when a `opentelemetry.trace.Span` is started.

    This method is called synchronously on the thread that starts the span, therefore it should not block or throw an exception.

    Parameters:

      - span (`Span`) – The `opentelemetry.trace.Span` that just started.

      - parent_context (`Context` | `None`) – The parent context of the span that just started.

    Return type:

      `None`

  on_end(span)

    Called when a `opentelemetry.trace.Span` is ended.

    This method is called synchronously on the thread that ends the span, therefore it should not block or throw an exception.

    Parameters:

      span (`ReadableSpan`) – The `opentelemetry.trace.Span` that just ended.

    Return type:

      `None`

  shutdown()

    Called when a `opentelemetry.sdk.trace.TracerProvider` is shutdown.

    Return type:

      `None`

  force_flush(timeout_millis=30000)

    Export all ended spans to the configured Exporter that have not yet been exported.

    Parameters:

      timeout_millis (`int`) – The maximum amount of time to wait for spans to be exported.

    Return type:

      `bool`

    Returns:

      False if the timeout is exceeded, True otherwise.

class opentelemetry.sdk.trace.export.BatchSpanProcessor(span_exporter, max_queue_size=None, schedule_delay_millis=None, max_export_batch_size=None, export_timeout_millis=None, *, meter_provider=None)

  Bases: `SpanProcessor`

  Batch span processor implementation.

  `BatchSpanProcessor` is an implementation of `SpanProcessor` that batches ended spans and pushes them to the configured `SpanExporter`.

  `BatchSpanProcessor` is configurable with the following environment variables which correspond to constructor parameters:

  - `OTEL_BSP_SCHEDULE_DELAY`

  - `OTEL_BSP_MAX_QUEUE_SIZE`

  - `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`

  - `OTEL_BSP_EXPORT_TIMEOUT`

  All the logic for emitting spans, shutting down etc. resides in the `BatchProcessor` class.

  property span_exporter
  on_start(span, parent_context=None)

    Called when a `opentelemetry.trace.Span` is started.

    This method is called synchronously on the thread that starts the span, therefore it should not block or throw an exception.

    Parameters:

      - span (`Span`) – The `opentelemetry.trace.Span` that just started.

      - parent_context (`Context` | `None`) – The parent context of the span that just started.

    Return type:

      `None`

  on_end(span)

    Called when a `opentelemetry.trace.Span` is ended.

    This method is called synchronously on the thread that ends the span, therefore it should not block or throw an exception.

    Parameters:

      span (`ReadableSpan`) – The `opentelemetry.trace.Span` that just ended.

    Return type:

      `None`

  shutdown()

    Called when a `opentelemetry.sdk.trace.TracerProvider` is shutdown.

  force_flush(timeout_millis=None)

    Export all ended spans to the configured Exporter that have not yet been exported.

    Parameters:

      timeout_millis (`int` | `None`) – The maximum amount of time to wait for spans to be exported.

    Return type:

      `bool`

    Returns:

      False if the timeout is exceeded, True otherwise.

class opentelemetry.sdk.trace.export.ConsoleSpanExporter(service_name=None, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, formatter=<function ConsoleSpanExporter.<lambda>>)

  Bases: `SpanExporter`

  Implementation of `SpanExporter` that prints spans to the console.

  This class can be used for diagnostic purposes. It prints the exported spans to the console STDOUT.

  export(spans)

    Exports a batch of telemetry data.

    Parameters:

      spans (`Sequence`[`ReadableSpan`]) – The list of `opentelemetry.trace.Span` objects to be exported

    Return type:

      `SpanExportResult`

    Returns:

      The result of the export

  force_flush(timeout_millis=30000)

    Hint to ensure that the export of any spans the exporter has received prior to the call to ForceFlush SHOULD be completed as soon as possible, preferably before returning from this method.

    Return type:

      `bool`