feat(node): Add ESM support for postgres.js instrumentation
Resolves: #17889
This PR rewrites the postgresjs instrumentation with a new architecture:
-
Added ESM support via
replaceExports -
Moved to main export wrapping instead of internal module patching
- Previously, we were patching
connection.jsandquery.jsinternal modules - New approach: We are wrapping the main postgres module export to intercept sql instance creation
- Previously, we were patching
-
Connection context is now stored directly on sql instances using
CONNECTION_CONTEXT_SYMBOL -
Query.prototypefallback (CJS only)- Patches
Query.prototype.handleas a fallback for pre-existing sql instances - Uses
QUERY_FROM_INSTRUMENTED_SQLmarker to prevent duplicate spans
- Patches
Also,
- Improved SQL sanitization
-
portattribute is now stored as a number per OTEL semantic conventions - Added fallback regex extraction for operation name when
commandisn't available
size-limit report 📦
| Path | Size | % Change | Change |
|---|---|---|---|
| @sentry/browser | 24.81 kB | - | - |
| @sentry/browser - with treeshaking flags | 23.3 kB | - | - |
| @sentry/browser (incl. Tracing) | 41.55 kB | - | - |
| @sentry/browser (incl. Tracing, Profiling) | 46.14 kB | - | - |
| @sentry/browser (incl. Tracing, Replay) | 79.97 kB | - | - |
| @sentry/browser (incl. Tracing, Replay) - with treeshaking flags | 69.7 kB | - | - |
| @sentry/browser (incl. Tracing, Replay with Canvas) | 84.64 kB | - | - |
| @sentry/browser (incl. Tracing, Replay, Feedback) | 96.89 kB | - | - |
| @sentry/browser (incl. Feedback) | 41.52 kB | - | - |
| @sentry/browser (incl. sendFeedback) | 29.49 kB | - | - |
| @sentry/browser (incl. FeedbackAsync) | 34.48 kB | - | - |
| @sentry/react | 26.52 kB | - | - |
| @sentry/react (incl. Tracing) | 43.75 kB | - | - |
| @sentry/vue | 29.27 kB | - | - |
| @sentry/vue (incl. Tracing) | 43.36 kB | - | - |
| @sentry/svelte | 24.82 kB | - | - |
| CDN Bundle | 27.24 kB | - | - |
| CDN Bundle (incl. Tracing) | 42.23 kB | - | - |
| CDN Bundle (incl. Tracing, Replay) | 78.75 kB | - | - |
| CDN Bundle (incl. Tracing, Replay, Feedback) | 84.21 kB | - | - |
| CDN Bundle - uncompressed | 80.04 kB | - | - |
| CDN Bundle (incl. Tracing) - uncompressed | 125.39 kB | - | - |
| CDN Bundle (incl. Tracing, Replay) - uncompressed | 241.42 kB | - | - |
| CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed | 254.18 kB | - | - |
| @sentry/nextjs (client) | 45.97 kB | - | - |
| @sentry/sveltekit (client) | 41.92 kB | - | - |
| @sentry/node-core | 51.5 kB | +0.01% | +1 B 🔺 |
| @sentry/node | 160.98 kB | +0.66% | +1.04 kB 🔺 |
| @sentry/node - without tracing | 92.91 kB | - | - |
| @sentry/aws-serverless | 108.44 kB | - | - |
node-overhead report 🧳
Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
| Scenario | Requests/s | % of Baseline | Prev. Requests/s | Change % |
|---|---|---|---|---|
| GET Baseline | 8,779 | - | 8,915 | -2% |
| GET With Sentry | 1,777 | 20% | 1,709 | +4% |
| GET With Sentry (error only) | 6,103 | 70% | 6,117 | -0% |
| POST Baseline | 1,207 | - | 1,215 | -1% |
| POST With Sentry | 607 | 50% | 593 | +2% |
| POST With Sentry (error only) | 1,062 | 88% | 1,060 | +0% |
| MYSQL Baseline | 3,384 | - | 3,317 | +2% |
| MYSQL With Sentry | 494 | 15% | 426 | +16% |
| MYSQL With Sentry (error only) | 2,725 | 81% | 2,654 | +3% |
...any updates?
@Lms24 - Implemented complete sanitization. https://github.com/getsentry/sentry-javascript/pull/17961/commits/4ae3e66f3474ca5a1bf692b646144bf0e12173e3