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

# Python [Logs]

> opentelemetry-instrument for FastAPI, Flask, Django — plus logging bridges.

## 1. Environment

```bash theme={null}
OTEL_SERVICE_NAME=my-service
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.tracelit.app
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer <WORKSPACE_INGEST_KEY>
```

## 2. Install

```bash theme={null}
python -m pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install
```

## 3. Launch

```bash theme={null}
opentelemetry-instrument <your-start-command>
```

Examples:

```bash theme={null}
opentelemetry-instrument uvicorn app:app --port 8000
opentelemetry-instrument python manage.py runserver
```

## 4. Log libraries

<Tabs>
  <Tab title="logging">
    Python standard library logging. `opentelemetry-bootstrap -a install` typically installs `opentelemetry-instrumentation-logging`. Keep using:

    ```python theme={null}
    import logging
    log = logging.getLogger(__name__)
    log.info("order listed", extra={"count": 3})
    log.error("payment failed")
    ```

    Start the process with `opentelemetry-instrument ...` so the instrumentation is active.
  </Tab>

  <Tab title="structlog">
    Configure structlog to also emit through stdlib logging (so `instrumentation-logging` picks them up), or add an OpenTelemetry processor.

    Minimal pattern: use `structlog.stdlib.LoggerFactory` and processors that end in `Printer` / `LoggerRenderer` bound to stdlib, then:

    ```python theme={null}
    log = structlog.get_logger()
    log.info("order listed", count=3)
    log.error("payment failed", err=str(err))
    ```
  </Tab>

  <Tab title="loguru">
    Add a sink that forwards to stdlib logging (recommended with `opentelemetry-instrument`) or emits OTLP records directly.

    ```python theme={null}
    from loguru import logger
    logger.info("order listed count={}", 3)
    logger.error("payment failed: {}", err)
    ```

    Without a sink/bridge, loguru output stays local and will not appear in Tracelit.
  </Tab>
</Tabs>

## 5. Verify

Produce **one INFO log** and **one ERROR log**, then confirm both in Tracelit Logs (or the onboarding live preview).
