- Install the OTLP HTTP exporter package.
- Import and configure the OTLP log exporter.
- Wire the exporter into the SDK’s log pipeline.
- Run the app and verify the Collector receives the logs.
Before running the code, install the OTLP HTTP exporter package:
What we’ll change
- Keep the span exporter (ConsoleSpanExporter) if you want to continue viewing spans locally.
- Configure an OTLP log exporter to point at the Collector HTTP endpoint (default path for OTLP logs is
/v1/logson port4318). - Create a
BatchLogRecordProcessorand attach it to the SDKLoggerProvider. - Optionally capture stdlib
loggingrecords and forward them to OpenTelemetry logs.
Imports and configuration
Notes:- Use
opentelemetry.exporter.otlp.proto.http._log_exporter.OTLPLogExporterfor the OTLP HTTP logs exporter (module and class names are case-sensitive). - If you also want to send spans to OTLP, add the corresponding OTLP span exporter (for example,
opentelemetry.exporter.otlp.proto.http.trace_exporter.OTLPSpanExporter) and a span processor.
Docker Compose — Local Collector
This minimal Docker Compose example runs an OpenTelemetry Collector that accepts both OTLP gRPC (4317) and OTLP HTTP (4318). It mounts a local config file into the container.Verify the Collector received logs
- Start the Collector via Docker Compose.
- Run your application configured with the OTLP log exporter.
- If the Collector routes logs to a stdout exporter in its config, you should see decoded log records in the Collector’s console.
- The application forwarded logs via OTLP to the Collector.
- The Collector decoded the OTLP payload and exposed metadata (severity, file/line attributes, trace/span IDs).
If you do not see logs in the Collector stdout:
- Verify your application can reach
http://localhost:4318. - Confirm the Collector config includes an OTLP receiver and a stdout (or other) exporter.
- Check for network/firewall rules or Docker port mappings that might block port 4318.
Troubleshooting checklist
- Is the OTLP exporter package installed? (
pip show opentelemetry-exporter-otlp-proto-http) - Is the Collector running and listening on the expected ports? (
docker psanddocker logs otel-collector) - Is the Collector config mounting correctly? Ensure
--config /etc/otel-collector-config.yamlpoints to the expected file. - Are there authentication or proxy requirements in your environment? If so, adjust
OTLPLogExporter(endpoint=...)or use environment variables per the exporter docs.
Links and references
- OpenTelemetry Collector: https://opentelemetry.io/docs/collector/
- OTLP HTTP logs exporter (PyPI): https://pypi.org/project/opentelemetry-exporter-otlp-proto-http/
- OpenTelemetry Python documentation: https://opentelemetry.io/docs/instrumentation/python/
- Docker Hub: https://hub.docker.com/
otel-collector-config.yaml example that routes OTLP logs to stdout and to a simple file exporter for local debugging.