feat(node): Add nodeRuntimeMetricsIntegration#19923
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Deps
Other
Bug Fixes 🐛Cloudflare
Core
Deps
Other
Internal Changes 🔧Deps Dev
Nuxt
Other
🤖 This preview updates automatically when you update the PR. |
size-limit report 📦
|
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.
|
…google-cloud-serverless, skip for bun Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
nodeRuntimeMetricsIntegrationnodeRuntimeMetricsIntegration
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed:
process.onceprevents serverless flush after first invocation- Changed process.once to process.on so the beforeExit listener fires on every serverless invocation, not just the first one.
Or push these changes by commenting:
@cursor push 152bf6699a
Preview (152bf6699a)
diff --git a/packages/node-core/src/integrations/nodeRuntimeMetrics.ts b/packages/node-core/src/integrations/nodeRuntimeMetrics.ts
--- a/packages/node-core/src/integrations/nodeRuntimeMetrics.ts
+++ b/packages/node-core/src/integrations/nodeRuntimeMetrics.ts
@@ -202,7 +202,7 @@
// Collect and flush at the end of every invocation. In non-serverless environments
// flushIfServerless is a no-op, so this is safe to call unconditionally.
- process.once('beforeExit', () => {
+ process.on('beforeExit', () => {
collectMetrics();
void flushIfServerless();
});This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
…ener Fixes the beforeExit listener to fire on every invocation in serverless warm starts (e.g. AWS Lambda). Also properly removes the old listener on re-init to avoid accumulation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Lms24
left a comment
There was a problem hiding this comment.
Nice! Had some questions/minor suggestions but nice! TIL about the event loop metrics.
dev-packages/node-integration-tests/suites/node-runtime-metrics/test.ts
Outdated
Show resolved
Hide resolved
Framework wrappers (SvelteKit, TanStack, etc.) already call flushIfServerless after each request handler. The beforeExit flush was redundant and introduced an infinite loop risk since Node.js re-emits beforeExit after async work completes. Metrics are sent by the periodic interval or the existing SDK flush infrastructure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rtions in tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
…meMetricsIntegration Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…s in integration tests ArrayContaining items are matched with strict equals (subsetEquality is not propagated), so extra attributes like sentry.timestamp.sequence and server.address caused all arrayContaining matches to fail. Wrapping with expect.objectContaining allows extra keys. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Lms24
left a comment
There was a problem hiding this comment.
Thanks for adding my suggestions!


Adds
nodeRuntimeMetricsIntegrationto@sentry/nodeand@sentry/node-core. When enabled, the integration periodically collects Node.js runtime health metrics and emits them to Sentry via the metrics pipeline.Usage
Default metrics (8)
Emitted every 30 seconds out of the box:
node.runtime.mem.rssnode.runtime.mem.heap_usednode.runtime.mem.heap_totalheap_usedto see headroomnode.runtime.cpu.utilizationnode.runtime.event_loop.delay.p50node.runtime.event_loop.delay.p99node.runtime.event_loop.utilizationnode.runtime.process.uptimeOpt-in metrics (off by default)
Any default metric can also be turned off:
Collection interval
Serverless (Next.js on Vercel, AWS Lambda, etc.)
Works out of the box — no special configuration needed. Metrics are sent by the periodic collection interval and flushed by the existing SDK flush infrastructure (framework wrappers like SvelteKit, TanStack Start, and
@sentry/aws-serverlessalready callflushIfServerlessafter each request handler). The interval isunref()-ed so it never prevents the process from exiting.Runtime compatibility
This integration is Node.js only. Bun and Deno will be addressed in separate integrations that use their respective native APIs.
Closes #19967 (added automatically)