Skip to content

feat(bun): Add bunRuntimeMetricsIntegration#19979

Merged
chargome merged 20 commits intodevelopfrom
feat/bun-runtime-metrics
Mar 27, 2026
Merged

feat(bun): Add bunRuntimeMetricsIntegration#19979
chargome merged 20 commits intodevelopfrom
feat/bun-runtime-metrics

Conversation

@chargome
Copy link
Copy Markdown
Member

Adds a new bunRuntimeMetricsIntegration that collects runtime metrics on a configurable interval using process.memoryUsage(), process.cpuUsage(), performance.eventLoopUtilization(), and process.uptime().

Default metrics (bun.runtime.* prefix):

  • mem.rss, mem.heap_used, mem.heap_total
  • cpu.utilization
  • event_loop.utilization
  • process.uptime

Opt-in: cpuTime (cpu.user, cpu.system), memExternal (mem.external, mem.array_buffers)

vs. nodeRuntimeMetricsIntegration: No event loop delay histogram metrics (monitorEventLoopDelay is
unavailable in Bun). ELU is guarded with try/catch for older Bun versions. Uses bun.runtime.* prefix and
auto.bun.runtime_metrics origin.

Includes unit tests (bun:test) and integration tests.

closes https://linear.app/getsentry/issue/JS-1956/runtime-metrics-bun-support

@linear-code
Copy link
Copy Markdown

linear-code bot commented Mar 25, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Deps

  • Bump babel-loader from 10.0.0 to 10.1.1 by dependabot in #19997
  • Bump handlebars from 4.7.7 to 4.7.9 by dependabot in #20008

Other

  • (browser) Replace element timing spans with metrics by logaretm in #19869
  • (bun) Add bunRuntimeMetricsIntegration by chargome in #19979
  • (core) Support embedding APIs in google-genai by nicohrubec in #19797
  • (node) Add nodeRuntimeMetricsIntegration by chargome in #19923
  • (nuxt) Support parametrized SSR routes in Nuxt 5 by s1gr1d in #19977

Bug Fixes 🐛

  • (e2e) Pin @opentelemetry/api to 1.9.0 in ts3.8 test app by logaretm in #19992
  • (node) Ensure startNewTrace propagates traceId in OTel environments by logaretm in #19963
  • (opentelemetry) Convert seconds timestamps in span.end() to milliseconds by logaretm in #19958

Documentation 📚

  • (release) Update publishing-a-release.md by nicohrubec in #19982

Internal Changes 🔧

Core

  • Introduce instrumented method registry for AI integrations by nicohrubec in #19981
  • Consolidate getOperationName into one shared utility by nicohrubec in #19971

Deps

  • Bump amqplib from 0.10.7 to 0.10.9 by dependabot in #20000
  • Bump actions/upload-artifact from 6 to 7 by dependabot in #19569
  • Bump srvx from 0.11.12 to 0.11.13 by dependabot in #20001
  • Bump @apollo/server from 5.4.0 to 5.5.0 by dependabot in #20007

Deps Dev

  • Bump node-forge from 1.3.2 to 1.4.0 by dependabot in #20012
  • Bump yaml from 2.8.2 to 2.8.3 by dependabot in #19985

Other

  • (deno) Expand Deno E2E test coverage by chargome in #19957
  • (e2e) Add e2e tests for nodeRuntimeMetricsIntegration by chargome in #19989

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 25.69 kB - -
@sentry/browser - with treeshaking flags 24.17 kB - -
@sentry/browser (incl. Tracing) 42.17 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.79 kB - -
@sentry/browser (incl. Tracing, Replay) 80.98 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.6 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 85.7 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 97.97 kB - -
@sentry/browser (incl. Feedback) 42.48 kB - -
@sentry/browser (incl. sendFeedback) 30.35 kB - -
@sentry/browser (incl. FeedbackAsync) 35.4 kB - -
@sentry/browser (incl. Metrics) 26.96 kB - -
@sentry/browser (incl. Logs) 27.1 kB - -
@sentry/browser (incl. Metrics & Logs) 27.78 kB - -
@sentry/react 27.45 kB - -
@sentry/react (incl. Tracing) 44.52 kB - -
@sentry/vue 30.13 kB - -
@sentry/vue (incl. Tracing) 44.08 kB - -
@sentry/svelte 25.7 kB - -
CDN Bundle 28.39 kB - -
CDN Bundle (incl. Tracing) 43.2 kB - -
CDN Bundle (incl. Logs, Metrics) 29.76 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 44.25 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.56 kB - -
CDN Bundle (incl. Tracing, Replay) 80.08 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 81.16 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 85.62 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.67 kB - -
CDN Bundle - uncompressed 82.93 kB - -
CDN Bundle (incl. Tracing) - uncompressed 128.07 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 87.07 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 131.48 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 210.06 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.95 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 248.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.86 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 261.25 kB - -
@sentry/nextjs (client) 46.93 kB - -
@sentry/sveltekit (client) 42.67 kB - -
@sentry/node-core 56.51 kB +0.02% +11 B 🔺
@sentry/node 173.61 kB +0.01% +13 B 🔺
@sentry/node - without tracing 96.54 kB +0.01% +5 B 🔺
@sentry/aws-serverless 113.54 kB +0.01% +9 B 🔺

View base workflow run

@chargome chargome self-assigned this Mar 26, 2026
chargome and others added 17 commits March 26, 2026 12:19
…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>
…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>
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>
…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>
Mirrors nodeRuntimeMetricsIntegration but adapted for Bun:
- Same CPU, memory, ELU, and uptime metrics
- No event loop delay percentiles (monitorEventLoopDelay not available in Bun)
- ELU wrapped in try/catch for forward compatibility with older Bun versions
- Metrics use bun.runtime.* prefix and auto.bun.runtime_metrics origin
- BunRuntimeMetricsOptions reuses NodeRuntimeMetricsOptions collect shape
  (minus the unsupported eventLoopDelay* flags)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds node-integration-tests scenarios that exercise the bun integration
using @sentry/node for init (bunRuntimeMetricsIntegration is Node-compatible
since it only uses perf_hooks and process.*).

Four test scenarios:
- default metrics shape (6 metrics with correct attributes/units)
- opt-in metrics not emitted by default
- all metrics when cpuTime + memExternal opted in
- opt-out leaves only memory metrics

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chargome chargome force-pushed the feat/bun-runtime-metrics branch from bc1c167 to 33f816b Compare March 26, 2026 11:19
@chargome chargome marked this pull request as ready for review March 26, 2026 13:04
@chargome chargome requested review from a team, mydea and nicohrubec and removed request for a team and mydea March 26, 2026 13:04
@chargome chargome requested review from a team, JPeer264, Lms24 and s1gr1d and removed request for a team and JPeer264 March 26, 2026 13:04
Comment on lines +5 to +18
### Important Changes

- **feat(node, bun): Add runtime metrics integrations for Node.js and Bun ([#19923](https://github.com/getsentry/sentry-javascript/pull/19923), [#19979](https://github.com/getsentry/sentry-javascript/pull/19979))**

New `nodeRuntimeMetricsIntegration` and `bunRuntimeMetricsIntegration` automatically collect runtime health metrics and send them to Sentry on a configurable interval (default: 30s). Collected metrics include memory (RSS, heap used/total), CPU utilization, event loop utilization, and process uptime. Node additionally collects event loop delay percentiles (p50, p99). Extra metrics like CPU time and external memory are available as opt-in.

```ts
// Node.js
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: '...',
integrations: [Sentry.nodeRuntimeMetricsIntegration()],
});
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the note for node again bc this was somehow lost in the gitflow merge (?)

chargome added a commit to getsentry/sentry-docs that referenced this pull request Mar 27, 2026
Document the new bunRuntimeMetricsIntegration for collecting Bun
runtime health metrics (memory, CPU, event loop, uptime).

Ref: getsentry/sentry-javascript#19979

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Explicitly pick the metrics available in Bun rather than omitting
Node-only fields, so new Node metrics don't silently leak into Bun.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@nicohrubec nicohrubec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@github-actions
Copy link
Copy Markdown
Contributor

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,829 - 9,185 -4%
GET With Sentry 1,706 19% 1,624 +5%
GET With Sentry (error only) 6,272 71% 6,039 +4%
POST Baseline 1,215 - 1,196 +2%
POST With Sentry 589 48% 581 +1%
POST With Sentry (error only) 1,039 86% 1,052 -1%
MYSQL Baseline 3,221 - 3,240 -1%
MYSQL With Sentry 474 15% 468 +1%
MYSQL With Sentry (error only) 2,611 81% 2,629 -1%

View base workflow run

@chargome chargome merged commit b93ef56 into develop Mar 27, 2026
240 checks passed
@chargome chargome deleted the feat/bun-runtime-metrics branch March 27, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants