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.create({
    "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)[source]

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

Bases: SpanExporter

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.

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, max_export_batch_size=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: LogRecordExporter

export(batch)[source]

Exports a batch of logs.

Parameters:

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

Return type:

LogRecordExportResult

Returns:

The result of the export.

Raises:

Exception – This method may raise exceptions on network errors, timeouts, or other failures. Callers (i.e., log processors) should handle these exceptions to comply with OpenTelemetry error handling principles.

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.create({
    "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