Skip to main content
Logs support in the OpenTelemetry Python SDK is currently experimental and subject to change. To check the status for each language, refer to the OpenTelemetry status page.
This example shows how to configure the OpenTelemetry Python SDK with declarative configuration to send logs from a Python application to Honeycomb or an OpenTelemetry Collector.
1

Acquire Dependencies

Install the OpenTelemetry distro, instrumentation, and OTLP exporter packages:
2

Create a Config File

Create an otelconfig.yaml file to configure your exporter.To send logs to Honeycomb:
To send logs to an OpenTelemetry Collector instead:
When OTEL_CONFIG_FILE is set, the configuration file is the single source of truth for the SDK. Other OTEL_* environment variables are ignored by design, so set all SDK options in the YAML file. You can still reference environment variables from inside the YAML using ${VAR_NAME} substitution.
3

Enable Python Standard Library Logging

Attach the OpenTelemetry LoggingHandler to the root logger during application startup so that standard library logging records reach the configured logger provider:
This step is a temporary workaround. Under OTEL_CONFIG_FILE, the OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED variable is ignored, so the handler must be attached manually. It will not be required in a future release. Upstream work is tracked in open-telemetry/opentelemetry-python#5352.
4

Run Your Application

Point the SDK at your configuration file using OTEL_CONFIG_FILE, then run your application: