# OpenTelemetry OTLP Exporters

## opentelemetry.exporter.otlp.proto.http

This library allows to export tracing data to an OTLP collector.

### Usage

The OTLP Span Exporter allows to export OpenTelemetry traces to the OTLP collector.

You can configure the exporter with the following environment variables:

- `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`

- `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL`

- `OTEL_EXPORTER_OTLP_TRACES_HEADERS`

- `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`

- `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION`

- `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE`

- `OTEL_EXPORTER_OTLP_TIMEOUT`

- `OTEL_EXPORTER_OTLP_PROTOCOL`

- `OTEL_EXPORTER_OTLP_HEADERS`

- `OTEL_EXPORTER_OTLP_ENDPOINT`

- `OTEL_EXPORTER_OTLP_COMPRESSION`

- `OTEL_EXPORTER_OTLP_CERTIFICATE`

    from opentelemetry import trace
    from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
    from opentelemetry.sdk.resources import Resource
    from opentelemetry.sdk.trace import TracerProvider
    from opentelemetry.sdk.trace.export import BatchSpanProcessor

    # Resource can be required for some backends, e.g. Jaeger
    # If resource wouldn't be set - traces wouldn't appears in Jaeger
    resource = Resource(attributes={
        "service.name": "service"
    })

    trace.set_tracer_provider(TracerProvider(resource=resource))
    tracer = trace.get_tracer(__name__)

    otlp_exporter = OTLPSpanExporter()

    span_processor = BatchSpanProcessor(otlp_exporter)

    trace.get_tracer_provider().add_span_processor(span_processor)

    with tracer.start_as_current_span("foo"):
        print("Hello world!")

### API

class opentelemetry.exporter.otlp.proto.http.Compression(*values)

  Bases: `Enum`

  NoCompression = 'none'
  Deflate = 'deflate'
  Gzip = 'gzip'

class opentelemetry.exporter.otlp.proto.http.trace_exporter.OTLPSpanExporter(endpoint=None, certificate_file=None, client_key_file=None, client_certificate_file=None, headers=None, timeout=None, compression=None, session=None)

  Bases: `SpanExporter`

  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.

  force_flush(timeout_millis=30000)

    Nothing is buffered in this exporter, so this method does nothing.

    Return type:

      `bool`

class opentelemetry.exporter.otlp.proto.http.metric_exporter.OTLPMetricExporter(endpoint=None, certificate_file=None, client_key_file=None, client_certificate_file=None, headers=None, timeout=None, compression=None, session=None, preferred_temporality=None, preferred_aggregation=None)

  Bases: `MetricExporter`, `OTLPMetricExporterMixin`

  export(metrics_data, timeout_millis=10000, **kwargs)

    Exports a batch of telemetry data.

    Parameters:

      metrics – The list of `opentelemetry.sdk.metrics.export.Metric` objects to be exported

    Return type:

      `MetricExportResult`

    Returns:

      The result of the export

  shutdown(timeout_millis=30000, **kwargs)

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`

  force_flush(timeout_millis=10000)

    Nothing is buffered in this exporter, so this method does nothing.

    Return type:

      `bool`

opentelemetry.exporter.otlp.proto.http.metric_exporter.get_resource_data(sdk_resource_scope_data, resource_class, name)
  Return type:

    `List`[`Resource`]

class opentelemetry.exporter.otlp.proto.http._log_exporter.OTLPLogExporter(endpoint=None, certificate_file=None, client_key_file=None, client_certificate_file=None, headers=None, timeout=None, compression=None, session=None)

  Bases: `LogRecordExporter`

  export(batch)

    Exports a batch of logs. :type batch: `Sequence`[`ReadableLogRecord`] :param batch: The list of `ReadableLogRecord` objects to be exported

    Return type:

      `LogRecordExportResult`

    Returns:

      The result of the export

  force_flush(timeout_millis=10000)

    Nothing is buffered in this exporter, so this method does nothing.

    Return type:

      `bool`

  shutdown()

    Shuts down the exporter.

    Called when the SDK is shut down.

## opentelemetry.exporter.otlp.proto.grpc

This library allows to export tracing data to an OTLP collector.

### Usage

The OTLP Span Exporter allows to export OpenTelemetry traces to the OTLP collector.

You can configure the exporter with the following environment variables:

- `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`

- `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL`

- `OTEL_EXPORTER_OTLP_TRACES_HEADERS`

- `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`

- `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION`

- `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE`

- `OTEL_EXPORTER_OTLP_TIMEOUT`

- `OTEL_EXPORTER_OTLP_PROTOCOL`

- `OTEL_EXPORTER_OTLP_HEADERS`

- `OTEL_EXPORTER_OTLP_ENDPOINT`

- `OTEL_EXPORTER_OTLP_COMPRESSION`

- `OTEL_EXPORTER_OTLP_CERTIFICATE`

    from opentelemetry import trace
    from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
    from opentelemetry.sdk.resources import Resource
    from opentelemetry.sdk.trace import TracerProvider
    from opentelemetry.sdk.trace.export import BatchSpanProcessor

    # Resource can be required for some backends, e.g. Jaeger
    # If resource wouldn't be set - traces wouldn't appears in Jaeger
    resource = Resource(attributes={
        "service.name": "service"
    })

    trace.set_tracer_provider(TracerProvider(resource=resource))
    tracer = trace.get_tracer(__name__)

    otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True)

    span_processor = BatchSpanProcessor(otlp_exporter)

    trace.get_tracer_provider().add_span_processor(span_processor)

    with tracer.start_as_current_span("foo"):
        print("Hello world!")

### API

OTLP Span Exporter

class opentelemetry.exporter.otlp.proto.grpc.trace_exporter.OTLPSpanExporter(endpoint=None, insecure=None, credentials=None, headers=None, timeout=None, compression=None, channel_options=None)

  Bases: `SpanExporter`, `OTLPExporterMixin`[`Sequence`[`ReadableSpan`], `ExportTraceServiceRequest`, `SpanExportResult`, `TraceServiceStub`]

  OTLP span exporter

  Parameters:

    - endpoint (`str` | `None`) – OpenTelemetry Collector receiver endpoint

    - insecure (`bool` | `None`) – Connection type

    - credentials (`ChannelCredentials` | `None`) – Credentials object for server authentication

    - headers (`Sequence`[`Tuple`[`str`, `str`]] | `Dict`[`str`, `str`] | `str` | `None`) – Headers to send when exporting

    - timeout (`float` | `None`) – Backend request timeout in seconds

    - compression (`Compression` | `None`) – gRPC compression method to use

  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(timeout_millis=30000, **kwargs)

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`

  force_flush(timeout_millis=30000)

    Nothing is buffered in this exporter, so this method does nothing.

    Return type:

      `bool`

class opentelemetry.exporter.otlp.proto.grpc.metric_exporter.OTLPMetricExporter(endpoint=None, insecure=None, credentials=None, headers=None, timeout=None, compression=None, preferred_temporality=None, preferred_aggregation=None, max_export_batch_size=None, channel_options=None)

  Bases: `MetricExporter`, `OTLPExporterMixin`[`MetricsData`, `ExportMetricsServiceRequest`, `MetricExportResult`, `MetricsServiceStub`], `OTLPMetricExporterMixin`

  OTLP metric exporter

  Parameters:

    - endpoint (`str` | `None`) – Target URL to which the exporter is going to send metrics

    - max_export_batch_size (`int` | `None`) – Maximum number of data points to export in a single request. This is to deal with gRPC’s 4MB message size limit. If not set there is no limit to the number of data points in a request. If it is set and the number of data points exceeds the max, the request will be split.

  export(metrics_data, timeout_millis=10000, **kwargs)

    Exports a batch of telemetry data.

    Parameters:

      metrics – The list of `opentelemetry.sdk.metrics.export.Metric` objects to be exported

    Return type:

      `MetricExportResult`

    Returns:

      The result of the export

  shutdown(timeout_millis=30000, **kwargs)

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`

  force_flush(timeout_millis=10000)

    Nothing is buffered in this exporter, so this method does nothing.

    Return type:

      `bool`

class opentelemetry.exporter.otlp.proto.grpc._log_exporter.OTLPLogExporter(endpoint=None, insecure=None, credentials=None, headers=None, timeout=None, compression=None, channel_options=None)

  Bases: `LogRecordExporter`, `OTLPExporterMixin`[`Sequence`[`ReadableLogRecord`], `ExportLogsServiceRequest`, `LogRecordExportResult`, `LogsServiceStub`]

  export(batch)

    Exports a batch of logs. :type batch: `Sequence`[`ReadableLogRecord`] :param batch: The list of `ReadableLogRecord` objects to be exported

    Return type:

      `Literal`[`<LogRecordExportResult.SUCCESS: 0>`, `<LogRecordExportResult.FAILURE: 1>`]

    Returns:

      The result of the export

  shutdown(timeout_millis=30000, **kwargs)

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`

  force_flush(timeout_millis=10000)

    Nothing is buffered in this exporter, so this method does nothing.

    Return type:

      `bool`