Skip to main content
In this lesson you’ll replace the console log exporter with an OTLP log exporter so application logs are forwarded to an OpenTelemetry Collector. In production you typically send traces and logs to a Collector, and the Collector forwards them to a backend such as Elasticsearch, Splunk, or a vendor-specific ingest. Overview
  • 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/logs on port 4318).
  • Create a BatchLogRecordProcessor and attach it to the SDK LoggerProvider.
  • Optionally capture stdlib logging records and forward them to OpenTelemetry logs.

Imports and configuration

Notes:
  • Use opentelemetry.exporter.otlp.proto.http._log_exporter.OTLPLogExporter for 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.
Example configuration (consolidated):

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

  1. Start the Collector via Docker Compose.
  2. Run your application configured with the OTLP log exporter.
  3. If the Collector routes logs to a stdout exporter in its config, you should see decoded log records in the Collector’s console.
Example Collector stdout output that indicates successful reception and decoding:
That output confirms:
  • 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 ps and docker logs otel-collector)
  • Is the Collector config mounting correctly? Ensure --config /etc/otel-collector-config.yaml points 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.
If you want, I can provide a ready-to-run otel-collector-config.yaml example that routes OTLP logs to stdout and to a simple file exporter for local debugging.

Watch Video

Practice Lab