Skip to main content
Send Python logs to Rootprint through the standard logging module, with the OpenTelemetry SDK’s OTLPLogExporter sending them over OTLP HTTP (http/protobuf).

Prerequisites

  • A running Rootprint instance. Substitute its host for <your-rootprint>.
  • Python 3.10+ with pip.
  • An ingest API key scoped to an OpenTelemetry logs index such as otel-logs-v0_9. In Settings → API keys, click Create ingest key and pick the index. See API keys.

Setup

1

Install the OpenTelemetry SDK

opentelemetry-instrumentation-logging provides the LoggingHandler that bridges the standard logging module.
2

Set environment variables

The %20 after Bearer is required: OpenTelemetry SDKs expect URL-encoded values in OTEL_EXPORTER_OTLP_LOGS_HEADERS.
3

Minimal working example

4

Verify in Rootprint

Open Logs, filter on service_name:my-python-service, and your record should appear within a few seconds.

Structured logging

Pass attributes in the extra argument of the standard logging API:
They land under attributes.user_id and attributes.plan, and you can search and filter on them.

Framework recipe: FastAPI

Set up the provider once at startup, in the app’s lifespan handler, so every worker process picks it up.

Troubleshooting

  • 401 or 403: the ingest API key is missing or wrong, or the space after Bearer isn’t written as %20. Check OTEL_EXPORTER_OTLP_LOGS_HEADERS. See Response codes.
  • 200 but no records in Logs: the ingest API key is scoped to an index without the OpenTelemetry logs schema, so the records are discarded. See Index target.
  • Nothing in Logs from a short-lived script: the batch processor buffers records. Shut down the logger provider before exit, as the minimal example does.
  • TLS errors against a self-signed endpoint: set OTEL_EXPORTER_OTLP_CERTIFICATE=/path/to/ca.pem.
  • OTLP reference: endpoint URL, response codes, env-var table
  • Indexes: otel-logs-v0_9 schema and custom-index concepts
  • Manage indexes: map log level, message, and traceback fields