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

# Monitor PostgreSQL (psycopg3) using OpenTelemetry

OpenLIT uses OpenTelemetry Auto-Instrumentation to help you monitor applications using PostgreSQL with the psycopg3 driver. This includes tracking query performance, transaction operations, connection pool metrics, and more.

Auto-instrumentation means you don't have to set up monitoring manually for different databases or query types. By simply adding OpenLIT in your application, all the necessary monitoring configurations are automatically set up.

The integration is compatible with

* psycopg `>= 3.0.0`
* psycopg\_pool (optional, for connection pool monitoring)

## Supported Operations

| Operation     | Description                            |
| ------------- | -------------------------------------- |
| `execute`     | Single query execution                 |
| `executemany` | Batch query execution                  |
| `copy`        | COPY operations for bulk data transfer |
| `callproc`    | Stored procedure calls                 |
| `commit`      | Transaction commits                    |
| `rollback`    | Transaction rollbacks                  |

## PostgreSQL-Specific Features

OpenLIT automatically detects and enriches traces with PostgreSQL-specific features:

* **pgvector Support**: Detects vector similarity operators (`<=>`, `<->`, `<#>`) and records the similarity metric (cosine, L2, inner product)
* **Full-Text Search**: Detects `tsvector`, `tsquery`, `websearch_to_tsquery`, and `ts_rank` operations

## Get started

<Steps>
  <Step title="Install OpenLIT">
    Open your command line or terminal and run:

    ```shell theme={null}
    pip install openlit
    ```
  </Step>

  <Step title="Initialize OpenLIT in your Application">
    <Tabs>
      <Tab title="Python">
        <Tabs>
          <Tab title="Zero Code Instrumentation">
            Perfect for existing applications - no code modifications needed:

            <Tabs>
              <Tab title="Via CLI Arguments">
                ```bash theme={null}
                # Configure via CLI arguments
                openlit-instrument \
                  --service-name my-ai-app \
                  --environment production \
                  --otlp-endpoint YOUR_OTEL_ENDPOINT \
                  python your_app.py
                ```
              </Tab>

              <Tab title="Via Environment Variables">
                ```bash theme={null}
                # Configure via environment variables
                export OTEL_SERVICE_NAME=my-ai-app
                export OTEL_DEPLOYMENT_ENVIRONMENT=production
                export OTEL_EXPORTER_OTLP_ENDPOINT=YOUR_OTEL_ENDPOINT

                # Run with zero code changes
                openlit-instrument python your_app.py
                ```
              </Tab>
            </Tabs>

            <Info>
              **Perfect for**: Legacy applications, production systems where code changes need approval, quick testing, or when you want to add observability without touching existing code.
            </Info>
          </Tab>

          <Tab title="One-Line Instrumentation">
            <Tabs>
              <Tab title="Via Function Parameters">
                ```python theme={null}
                import openlit

                openlit.init(otlp_endpoint="YOUR_OTEL_ENDPOINT")
                ```
              </Tab>

              <Tab title="Via Environment Variables">
                Add the following two lines to your application code:

                ```python theme={null}
                import openlit

                openlit.init()
                ```

                Then, configure the your OTLP endpoint using environment variable:

                ```shell theme={null}
                export OTEL_EXPORTER_OTLP_ENDPOINT=YOUR_OTEL_ENDPOINT
                ```
              </Tab>
            </Tabs>
          </Tab>
        </Tabs>
      </Tab>

      <Tab title="Typescript">
        <Tabs>
          <Tab title="One-Line Instrumentation (SDK)">
            <Tabs>
              <Tab title="Via Function Parameters">
                ```typescript theme={null}
                import openlit from "openlit"

                openlit.init({ otlpEndpoint: "YOUR_OTEL_ENDPOINT" })
                ```
              </Tab>

              <Tab title="Via Environment Variables">
                Add the following two lines to your application code:

                ```typescript theme={null}
                import openlit from "openlit"

                openlit.init()
                ```

                Then, configure the your OTLP endpoint using environment variable:

                ```shell theme={null}
                export OTEL_EXPORTER_OTLP_ENDPOINT=YOUR_OTEL_ENDPOINT
                ```
              </Tab>
            </Tabs>
          </Tab>
        </Tabs>
      </Tab>
    </Tabs>

    **Replace:** `YOUR_OTEL_ENDPOINT` with the URL of your OpenTelemetry backend, such as `http://127.0.0.1:4318` if you are using OpenLIT and a local OTel Collector.

    To send metrics and traces to other Observability tools, refer to the [supported destinations](/latest/sdk/destinations/overview).

    For more advanced configurations and application use cases, visit the [OpenLIT Python repository](https://github.com/openlit/openlit/tree/main/sdk/python) or [OpenLIT Typescript repository](https://github.com/openlit/openlit/tree/main/sdk/typescript).
  </Step>
</Steps>

## Advanced Configuration

### Database-Specific Options

OpenLIT provides additional configuration options for database instrumentation:

| Parameter               | Environment Variable            | Description                                                                  | Default |
| ----------------------- | ------------------------------- | ---------------------------------------------------------------------------- | ------- |
| `capture_db_parameters` | `OPENLIT_CAPTURE_DB_PARAMETERS` | Capture query parameters in OTel per-key format (`db.query.parameter.<key>`) | `False` |

### capture\_db\_parameters

When enabled, query parameters are recorded as per-key span attributes following the OTel semantic convention `db.query.parameter.<key>`.

```python theme={null}
import openlit

openlit.init(capture_db_parameters=True)
```

<Warning>
  **Security Risk**: Enabling `capture_db_parameters` may expose sensitive data like passwords, tokens, or PII in your traces. Only enable in development environments or when you're certain parameters don't contain sensitive information.
</Warning>

***

<CardGroup cols={3}>
  <Card title="Quickstart: Database Observability" href="/latest/sdk/quickstart-vectordb-observability" icon="bolt">
    Production-ready database monitoring setup in 2 simple steps
  </Card>

  <Card title="Configuration" href="/latest/sdk/configuration" icon="bolt">
    Configure the OpenLIT SDK according to your requirements.
  </Card>

  <Card title="Destinations" href="/latest/sdk/destinations/overview" icon="link">
    Send telemetry to Datadog, Grafana, New Relic, and other observability stacks
  </Card>
</CardGroup>

<Card title="Zero-code observability with the OpenLIT Controller" icon="tower-broadcast" href="/latest/controller/overview">
  Discover and instrument LLM traffic across Kubernetes, Docker, and Linux using eBPF — no code changes required.
</Card>
