This example shows how to export telemetry data to multiple destinations simultaneously. As described in the OTLP specification, each destination should have implemented its own queuing, acknowledgement handling, and retry logic to prevent one slow or unavailable destination from blocking the others.
The OpenTelemetry Python SDK achieves this by using a separate processor or reader per destination:
- Traces: Use one
BatchSpanProcessorper destination, each wrapping its ownSpanExporter. Add each processor to theTracerProviderviaadd_span_processor(). - Metrics: Pass multiple
MetricReaderinstances (each wrapping its ownMetricExporter) to theMeterProviderconstructor via themetric_readersparameter. - Logs: Use one
BatchLogRecordProcessorper destination, each wrapping its ownLogExporter. Add each processor to theLoggerProviderviaadd_log_record_processor().
Note
The Profiles signal is not yet supported in the Python SDK. When it becomes available, the same pattern will apply.
The source files of these examples are available :scm_web:`here <docs/examples/multi-destination-exporting/>`.
pip install opentelemetry-api
pip install opentelemetry-sdk
pip install opentelemetry-exporter-otlp-proto-grpc
pip install opentelemetry-exporter-otlp-proto-http
pip install opentelemetry-instrumentation-logging # For LoggingHandlerpython multi_destination_traces.py
python multi_destination_metrics.py
python multi_destination_logs.pyThe output will be shown in the console for the ConsoleSpanExporter,
ConsoleMetricExporter, and ConsoleLogRecordExporter destinations.
The OTLP destinations require a running collector.