OpenTelemetry Collector Exporters
The opentelemetry-exporter-otlp library provides OpenTelemetry Collector exporters, allowing users to send telemetry data to OpenTelemetry-supported backend systems. Current version: 1.40.0, released with a cadence of regular updates enhancing functionality and fixing issues.
Warnings
- breaking The behavior of start_span and start_as_current_span in NoOpTracer has changed; it now propagates the span context properly.
- deprecated LoggingHandler in opentelemetry-sdk is deprecated; use opentelemetry-instrumentation-logging instead.
Install
-
pip install opentelemetry-exporter-otlp
Imports
- OTLPSpanExporter
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
Quickstart
import os
from opentelemetry import trace
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.trace import set_tracer_provider
# Set up the OTLP exporter
exporter = OTLPSpanExporter(endpoint=os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', 'localhost:4317'))
set_tracer_provider(TracerProvider(resource=Resource.create({'service.name': 'example-service'})))
tracer = trace.get_tracer(__name__)
# Example usage
with tracer.start_as_current_span('example-span'):
print('Hello, OpenTelemetry!')