Skip to content

feat(bun): Add bunRuntimeMetricsIntegration#19979

Draft
chargome wants to merge 17 commits intodevelopfrom
feat/bun-runtime-metrics
Draft

feat(bun): Add bunRuntimeMetricsIntegration#19979
chargome wants to merge 17 commits intodevelopfrom
feat/bun-runtime-metrics

Conversation

@chargome
Copy link
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

chargome and others added 17 commits March 25, 2026 15:53
…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>
@linear-code
Copy link

linear-code bot commented Mar 25, 2026

@github-actions
Copy link
Contributor

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 mongodb-memory-server-global from 10.1.4 to 11.0.1 by dependabot in #19888
  • Bump stacktrace-parser from 0.1.10 to 0.1.11 by dependabot in #19887

Other

  • (bun) Add bunRuntimeMetricsIntegration by chargome in #19979
  • (elysia) Elysia SDK by logaretm in #19509
  • (node) Add nodeRuntimeMetricsIntegration by chargome in #19923
  • (nuxt) Conditionally use plugins based on Nitro version (v2/v3) by s1gr1d in #19955

Bug Fixes 🐛

Cloudflare

  • Send correct events in local development by JPeer264 in #19900
  • Forward ctx argument to Workflow.do user callback by Lms24 in #19891

Core

  • Preserve .withResponse() on Anthropic instrumentation by nicohrubec in #19935
  • Truncate content array format in Vercel by nicohrubec in #19911
  • Send internal_error as span status for Vercel error spans by nicohrubec in #19921
  • Do not overwrite user provided conversation id in Vercel by nicohrubec in #19903
  • Return same value from startSpan as callback returns by s1gr1d in #19300

Deps

  • Update lockfile to resolve h3@1.15.10 by chargome in #19933
  • Bump fast-xml-parser to 5.5.8 in @azure/core-xml chain by chargome in #19918
  • Bump next to 15.5.14 in nextjs-15 and nextjs-15-intl E2E test apps by chargome in #19917
  • Bump socket.io-parser to 4.2.6 to fix CVE-2026-33151 by chargome in #19880

Other

  • (craft) Add missing mainDocsUrl for @sentry/effect SDK by bc-sentry in #19860
  • (nestjs) Add node to nest metadata by chargome in #19875
  • (serverless) Add node to metadata by nicohrubec in #19878

Internal Changes 🔧

Deps Dev

  • Bump effect from 3.19.19 to 3.20.0 by dependabot in #19926
  • Bump qunit-dom from 3.2.1 to 3.5.0 by dependabot in #19546
  • Bump @react-router/node from 7.13.0 to 7.13.1 by dependabot in #19544

Nuxt

  • Extract core logic for storage/database to prepare for Nuxt v5 by s1gr1d in #19920
  • Extract handler patching to extra plugin for Nitro v2/v3 by s1gr1d in #19915

Other

  • (astro) Re-enable server island tracing e2e test in Astro 6 by Lms24 in #19872
  • (ci) Fix "Gatbsy" typo in issue package label workflow by chargome in #19905
  • (claude) Enable Claude Code Intelligence (LSP) by s1gr1d in #19930
  • (cloudflare) Enable multi-worker tests for CF integration tests by JPeer264 in #19938
  • (core) Remove duplicate buildMethodPath utility from openai by nicohrubec in #19969
  • (deno) Expand Deno E2E test coverage by chargome in #19957
  • (elysia) Drop @elysiajs/opentelemetry dependency by logaretm in #19947
  • (lint) Resolve oxlint warnings by isaacs in #19893
  • (node-integration-tests) Remove unnecessary file-type dependency by Lms24 in #19824
  • (remix) Replace glob with native recursive fs walk by roli-lpci in #19531
  • (sveltekit) Replace recast + @babel/parser with acorn by roli-lpci in #19533
  • Add external contributor to CHANGELOG.md by javascript-sdk-gitflow in #19925
  • Add external contributor to CHANGELOG.md by javascript-sdk-gitflow in #19909

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.69 kB - -
@sentry/browser - with treeshaking flags 24.17 kB - -
@sentry/browser (incl. Tracing) 42.67 kB - -
@sentry/browser (incl. Tracing, Profiling) 47.33 kB - -
@sentry/browser (incl. Tracing, Replay) 81.48 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 71.06 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 86.17 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 98.41 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) 45.01 kB - -
@sentry/vue 30.13 kB - -
@sentry/vue (incl. Tracing) 44.52 kB - -
@sentry/svelte 25.7 kB - -
CDN Bundle 28.35 kB - -
CDN Bundle (incl. Tracing) 43.57 kB - -
CDN Bundle (incl. Logs, Metrics) 29.22 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 44.43 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.29 kB - -
CDN Bundle (incl. Tracing, Replay) 80.41 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 81.31 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 85.97 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.86 kB - -
CDN Bundle - uncompressed 82.7 kB - -
CDN Bundle (incl. Tracing) - uncompressed 128.62 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.57 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 131.49 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 209.22 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 245.5 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 248.35 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 258.41 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 261.26 kB - -
@sentry/nextjs (client) 47.4 kB - -
@sentry/sveltekit (client) 43.12 kB - -
@sentry/node-core 56.42 kB +0.03% +13 B 🔺
@sentry/node 173.51 kB +0.01% +7 B 🔺
@sentry/node - without tracing 96.43 kB +0.01% +9 B 🔺
@sentry/aws-serverless 113.44 kB +0.01% +5 B 🔺

View base workflow run

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.

1 participant