Monitor PostgreSQL (psycopg3) using OpenTelemetry
Shield360 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 Shield360 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
Section titled “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
Section titled “PostgreSQL-Specific Features”Shield360 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, andts_rankoperations
Get started
Section titled “Get started”Open your command line or terminal and run:
pip install shield360Perfect for existing applications - no code modifications needed:
# Configure via CLI argumentsshield360-instrument \ --service-name my-ai-app \ --environment production \ --otlp-endpoint YOUR_OTEL_ENDPOINT \ python your_app.py# Configure via environment variablesexport OTEL_SERVICE_NAME=my-ai-appexport OTEL_DEPLOYMENT_ENVIRONMENT=productionexport OTEL_EXPORTER_OTLP_ENDPOINT=YOUR_OTEL_ENDPOINT
# Run with zero code changesshield360-instrument python your_app.pyimport shield360
shield360.init(otlp_endpoint="YOUR_OTEL_ENDPOINT")Add the following two lines to your application code:
import shield360
shield360.init()Then, configure the your OTLP endpoint using environment variable:
export OTEL_EXPORTER_OTLP_ENDPOINT=YOUR_OTEL_ENDPOINTimport shield360 from "shield360"
shield360.init({ otlpEndpoint: "YOUR_OTEL_ENDPOINT" })Add the following two lines to your application code:
import shield360 from "shield360"
shield360.init()Then, configure the your OTLP endpoint using environment variable:
export OTEL_EXPORTER_OTLP_ENDPOINT=YOUR_OTEL_ENDPOINTReplace: YOUR_OTEL_ENDPOINT with the URL of your OpenTelemetry backend, such as http://127.0.0.1:4318 if you are using Shield360 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 SDK configuration reference or TypeScript SDK reference.
Advanced Configuration
Section titled “Advanced Configuration”Database-Specific Options
Section titled “Database-Specific Options”Shield360 provides additional configuration options for database instrumentation:
| Parameter | Environment Variable | Description | Default |
|---|---|---|---|
capture_db_parameters | SHIELD360_CAPTURE_DB_PARAMETERS | Capture query parameters in OTel per-key format (db.query.parameter.<key>) | False |
capture_db_parameters
Section titled “capture_db_parameters”When enabled, query parameters are recorded as per-key span attributes following the OTel semantic convention db.query.parameter.<key>.
import shield360
shield360.init(capture_db_parameters=True)