Skip to main content
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

OperationDescription
executeSingle query execution
executemanyBatch query execution
copyCOPY operations for bulk data transfer
callprocStored procedure calls
commitTransaction commits
rollbackTransaction 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

1

Install OpenLIT

Open your command line or terminal and run:
pip install openlit
2

Initialize OpenLIT in your Application

Perfect for existing applications - no code modifications needed:
# Configure via CLI arguments
openlit-instrument \
  --service-name my-ai-app \
  --environment production \
  --otlp-endpoint YOUR_OTEL_ENDPOINT \
  python your_app.py
Perfect for: Legacy applications, production systems where code changes need approval, quick testing, or when you want to add observability without touching existing code.
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.For more advanced configurations and application use cases, visit the OpenLIT Python repository or OpenLIT Typescript repository.

Advanced Configuration

Database-Specific Options

OpenLIT provides additional configuration options for database instrumentation:
ParameterEnvironment VariableDescriptionDefault
capture_parametersOPENLIT_CAPTURE_PARAMETERSCapture query parameters in spansFalse
enable_sqlcommenterOPENLIT_ENABLE_SQLCOMMENTERInject trace context as SQL commentsFalse

capture_parameters

When enabled, query parameters are recorded in span attributes for debugging purposes.
import openlit

openlit.init(capture_parameters=True)
Security Risk: Enabling capture_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.

enable_sqlcommenter (SQLCommenter)

When enabled, OpenLIT injects OpenTelemetry trace context into SQL queries as comments. This enables correlation between application traces and database logs.
import openlit

openlit.init(enable_sqlcommenter=True)
Example query transformation:
-- Original query
SELECT * FROM users WHERE id = $1;

-- With SQLCommenter enabled
SELECT * FROM users WHERE id = $1 /*traceparent='00-abc123def456-789xyz-01',application='my_app'*/;
Benefits:
  • Correlate slow queries in pg_stat_statements with application traces
  • Link EXPLAIN ANALYZE output to specific requests
  • Debug performance issues across application and database layers

Running in Kubernetes? Try the OpenLIT Operator

Automatically inject instrumentation into existing workloads without modifying pod specs, container images, or application code.