feat(postgres): add Postgres.js tracing - #10125
Conversation
Overall package sizeSelf size: 8.84 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.4.0 | 127.33 kB | 447.04 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10125 +/- ##
========================================
Coverage 98.65% 98.65%
========================================
Files 1005 1009 +4
Lines 157435 157847 +412
Branches 74 74
========================================
+ Hits 155312 155724 +412
Misses 2123 2123
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
BenchmarksBenchmark execution time: 2026-09-04 23:38:18 Comparing candidate commit 6d2af20 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2307 metrics, 6 unstable metrics.
|
8dcf731 to
51a4551
Compare
| tracer.use('pg', { truncate: 5000 }); | ||
| tracer.use('pino'); | ||
| tracer.use('postgres'); | ||
| tracer.use('postgres', { service: 'postgres-service' }); |
There was a problem hiding this comment.
we are moving away from allowing configurable per integration service name, can this be removed along with the optional configuration
There was a problem hiding this comment.
I believe doing this only for some is not ideal. Otherwise it is likely confusing for customers. I believe it would also require special handling to prevent it (I believe it is a generic functionality)
Postgres.js keeps lazy queries and connection handlers in module-local closures. A Query can also settle after cursor replacement or retry. Instrument the source-owned dispatch and settlement boundaries to keep one span across queues, cursors, retries, and cancellations. Fixes: #2644
Postgres.js retains host and port values when a socket path is active, which made Unix-socket spans report a TCP endpoint that was not used.
Postgres.js uses whole-program transforms that do not share the generic transform contract.
51a4551 to
6d2af20
Compare
What does this PR do?
Adds automatic tracing for Postgres.js 3.x in CommonJS and ESM.
It starts spans when lazy queries enter a connection handler and finishes them at final Query settlement. Query identity and public methods remain unchanged.
The plugin reports compiled SQL resources, PostgreSQL database and endpoint tags, schema-aware names, peer service, truncation, and errors.
Motivation
Postgres.js is not currently instrumented, so applications using it do not emit database spans.
Its connection handlers and Query settlement functions remain in module-local closures, which makes runtime export wrapping incomplete.
Additional Notes
The real PostgreSQL matrix runs against 3.0.0 and 3.4.9 in CommonJS and ESM. It covers:
Postgres.js 1.x is excluded because it has a different internal architecture.
This does not add DBM propagation, AppSec query blocking, or a separate pool span.
Refs #2644