Skip to main content
The Postgres integration automatically instruments the 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 the pg 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

Query parameters are captured in spans. Be careful with sensitive data.

Filtering Sensitive Data

Source Code

The Postgres integration is implemented in: packages/node/src/integrations/tracing/postgres.ts:24

Best Practices

Use connection pooling for better performance and resource management.

1. Use Connection Pools

2. Handle Errors Properly

3. Use Prepared Statements

4. Monitor Connection Pool

Troubleshooting

Spans Not Appearing

Ensure tracing is enabled:

Missing Query Text

Query text should be automatically captured. If missing, check:

Too Many Connection Spans

Disable connection tracking: