pg (node-postgres) library to capture database query performance and errors.
Installation
The integration is enabled by default in Node.js:Basic Usage
Just use thepg library normally:
Configuration
Default Configuration
Ignore Connection Spans
If you want to track only queries and not connections:Integration Options
boolean
default:"false"
Whether to ignore database connection spans
What Gets Captured
The integration captures:Query Operations
- SQL query text
- Query parameters
- Execution time
- Row counts
- Database name
- Connection details
Span Attributes
Supported Operations
Simple Queries
Parameterized Queries
Prepared Statements
Transactions
Practical Examples
Basic CRUD Operations
Connection Pool
Complex Queries
Async/Await with Error Handling
Cursor-based Pagination
Transaction with Savepoints
Performance Monitoring
View database performance in Sentry:Metrics Tracked
- Query Duration: Time taken for each query
- Query Count: Number of queries per transaction
- Slow Queries: Identify performance bottlenecks
- Error Rates: Track failed queries
Query Parameterization
Filtering Sensitive Data
Source Code
The Postgres integration is implemented in:packages/node/src/integrations/tracing/postgres.ts:24