> ## Documentation Index
> Fetch the complete documentation index at: https://docs.honeycomb.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Example: Send OpenTelemetry Logs with the OpenTelemetry Python SDK

> Configure the OpenTelemetry Python SDK logger provider to send structured logs from your Python application to Honeycomb or a Collector.

<Note>
  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](https://opentelemetry.io/status/).
</Note>

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.

<Steps titleSize="h2">
  <Step title="Acquire Dependencies">
    Install the OpenTelemetry distro, instrumentation, and OTLP exporter packages:

    ```shell theme={}
    pip install opentelemetry-distro \
        opentelemetry-instrumentation \
        opentelemetry-exporter-otlp
    ```
  </Step>

  <Step title="Create a Config File">
    Create an `otelconfig.yaml` file to configure your exporter.

    To send logs to Honeycomb:

    ```yaml theme={}
    file_format: "1.0"

    resource:
      attributes:
        - name: service.name
          value: ${OTEL_SERVICE_NAME:-my-service}

    logger_provider:
      processors:
        - batch:
            exporter:
              otlp_http:
                endpoint: https://api.honeycomb.io/v1/logs
                headers:
                  - name: x-honeycomb-team
                    value: ${HONEYCOMB_API_KEY}
    ```

    To send logs to an OpenTelemetry Collector instead:

    ```yaml theme={}
    file_format: "1.0"

    resource:
      attributes:
        - name: service.name
          value: ${OTEL_SERVICE_NAME:-my-service}

    logger_provider:
      processors:
        - batch:
            exporter:
              otlp_grpc:
                endpoint: http://my-collector:4317
    ```

    <Note>
      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.
    </Note>
  </Step>

  <Step title="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:

    ```python theme={}
    import logging
    from opentelemetry._logs import get_logger_provider
    from opentelemetry.sdk._logs import LoggingHandler

    logging.getLogger().addHandler(
        LoggingHandler(logger_provider=get_logger_provider())
    )

    # Use logging directly anywhere in your app
    logging.warning("Something interesting happened")
    ```

    <Note>
      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](https://github.com/open-telemetry/opentelemetry-python/issues/5352).
    </Note>
  </Step>

  <Step title="Run Your Application">
    Point the SDK at your configuration file using `OTEL_CONFIG_FILE`, then run your application:

    ```shell theme={}
    OTEL_CONFIG_FILE=./otelconfig.yaml opentelemetry-instrument python app.py
    ```
  </Step>
</Steps>
