Add DB pool observability, OTel pg instrumentation, and statement_timeout#520
Merged
Add DB pool observability, OTel pg instrumentation, and statement_timeout#520
Conversation
…eout - Log pool metrics (totalCount, idleCount, waitingCount) every 30s as structured JSON, picked up by Vercel log drain → Axiom - Register @opentelemetry/instrumentation-pg in OTel setup to get per-query spans (duration, errors) in Sentry traces - Enforce POSTGRES_MAX_QUERY_TIME as statement_timeout on both primary and replica pools (was validated as required but never applied)
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Clean, well-structured change that adds two improvements to the database connection layer:
Files Reviewed (1 file)
|
…Integration Sentry's postgresIntegration (enabled by default) uses the same @opentelemetry/instrumentation-pg under the hood. Adding it explicitly in registerOTel would double-instrument pg queries.
jeanduplessis
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds application-side database observability and enforces the
statement_timeoutguard that was validated but never applied.1. Pool metrics → Axiom (via Vercel log drain)
Logs
pool.totalCount,pool.idleCount, andpool.waitingCountevery 30s as structured JSON for both primary and replica pools. This gives the client-side view of connection usage per Vercel instance/region, complementing the server-side view from the new Supabase → Grafana integration.Example log line:
{"type":"pool_metrics","region":"iad1","primary":{"total":8,"idle":5,"waiting":0},"replica":{"total":3,"idle":2,"waiting":0}}Queryable in Axiom with:
2.
statement_timeoutenforcementApplies
POSTGRES_MAX_QUERY_TIME(already validated as a required env var) asstatement_timeouton both primary and replica pools. Previously the env var was checked at startup but never actually used — queries had no server-side timeout guard.Not included: OTel pg instrumentation
Sentry's
postgresIntegration(enabled by default) already uses@opentelemetry/instrumentation-pgunder the hood, so per-query spans are already being captured in Sentry traces without any code change needed.Context
Follow-up to #497 (connection exhaustion fix). The Supabase dashboards provide limited visibility, so we're adding application-side observability to correlate with the new Grafana dashboards.
Changes
src/lib/drizzle.ts— pool metrics logging +statement_timeouton both pools