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:

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(value)[source]

Bases: Enum

An enumeration.

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)[source]

Bases: SpanExporter

export(spans)[source]

Exports a batch of telemetry data.

Parameters:

spans – The list of opentelemetry.trace.Span objects to be exported

Return type:

SpanExportResult

Returns:

The result of the export

shutdown()[source]

Shuts down the exporter.

Called when the SDK is shut down.

force_flush(timeout_millis=30000)[source]

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)[source]

Bases: MetricExporter, OTLPMetricExporterMixin

export(metrics_data, timeout_millis=10000, **kwargs)[source]

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)[source]

Shuts down the exporter.

Called when the SDK is shut down.

Return type:

None

force_flush(timeout_millis=10000)[source]

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)[source]
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)[source]

Bases: LogExporter

export(batch)[source]

Exports a batch of logs.

Parameters:

batch (Sequence[LogData]) – The list of LogData objects to be exported

Return type:

LogExportResult

Returns:

The result of the export

force_flush(timeout_millis=10000)[source]

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

Return type:

bool

shutdown()[source]

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:

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)[source]

Bases: SpanExporter, OTLPExporterMixin[ReadableSpan, ExportTraceServiceRequest, SpanExportResult]

OTLP span exporter

Parameters:
export(spans)[source]

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()[source]

Shuts down the exporter.

Called when the SDK is shut down.

Return type:

None

force_flush(timeout_millis=30000)[source]

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)[source]

Bases: MetricExporter, OTLPExporterMixin[Metric, ExportMetricsServiceRequest, MetricExportResult], OTLPMetricExporterMixin

OTLP metric exporter

Parameters:
  • endpoint (Optional[str]) – Target URL to which the exporter is going to send metrics

  • max_export_batch_size (Optional[int]) – 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)[source]

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)[source]

Shuts down the exporter.

Called when the SDK is shut down.

Return type:

None

force_flush(timeout_millis=10000)[source]

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)[source]

Bases: LogExporter, OTLPExporterMixin[LogRecord, ExportLogsServiceRequest, LogExportResult]

export(batch)[source]

Exports a batch of logs.

Parameters:

batch (Sequence[LogData]) – The list of LogData objects to be exported

Return type:

LogExportResult

Returns:

The result of the export

shutdown(timeout_millis=30000, **kwargs)[source]

Shuts down the exporter.

Called when the SDK is shut down.

Return type:

None

force_flush(timeout_millis=10000)[source]

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

Return type:

bool