Skip to content

feat(bun): Instrument modules in bun run on Bun 1.4.5 and later - #26515

Open
isaacs wants to merge 1 commit into
developfrom
feat/bun-run-tracing
Open

isaacs wants to merge 1 commit into
developfrom
feat/bun-run-tracing

Conversation

@isaacs

@isaacs isaacs commented Nov 17, 2026

Copy link
Copy Markdown
Member

Bun 1.4.5 fixes CommonJS modules that a runtime onLoad plugin returns (oven-sh/bun#19279). Before, they lost their named exports, so the orchestrion transform could only run in bun build.

Sentry.init() from @sentry/bun now registers the orchestrion transform with Bun.plugin(). The new @sentry/bun/import preload does the same before the app loads, so it also reaches the static imports of the entry module:

bun --preload @sentry/bun/import app.ts

On older Bun versions the SDK skips the registration, and the warning about missing channel injection tells users to upgrade Bun or build with @sentry/bun/plugin. enableRuntimeChannelInjection: false turns the registration off, as in @sentry/node.

The injected snippet imports @sentry/server-utils from inside the instrumented package. Under isolated installs that specifier does not resolve from there, so an onResolve hook points it at the copy of @sentry/server-utils that the SDK already loaded.

The new node-suites-bun-run integration project runs the auto-instrumentation suites unbuilt on Bun 1.4.5 or later, and CI runs the Bun integration tests on canary too, until 1.4.5 is released.

Bun 1.4.5 fixes CommonJS modules that a runtime `onLoad` plugin returns
(oven-sh/bun#19279). Before, they lost their named exports, so the
orchestrion transform could only run in `bun build`.

`Sentry.init()` from `@sentry/bun` now registers the orchestrion
transform with `Bun.plugin()`. The new `@sentry/bun/import` preload does
the same before the app loads, so it also reaches the static imports of
the entry module:

    bun --preload @sentry/bun/import app.ts

On older Bun versions the SDK skips the registration, and the warning
about missing channel injection tells users to upgrade Bun or build with
`@sentry/bun/plugin`. `enableRuntimeChannelInjection: false` turns the
registration off, as in `@sentry/node`.

The injected snippet imports `@sentry/server-utils` from inside the
instrumented package. Under isolated installs that specifier does not
resolve from there, so an `onResolve` hook points it at the copy of
`@sentry/server-utils` that the SDK already loaded.

The new `node-suites-bun-run` integration project runs the
auto-instrumentation suites unbuilt on Bun 1.4.5 or later, and CI runs
the Bun integration tests on canary too, until 1.4.5 is released.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 16871dc (PR test merge using develop at d44a8ba)

Against: d44a8ba (develop) · base run #66610

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.18 kB - -
@sentry/browser - with treeshaking flags 28.37 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.28 kB - -
@sentry/browser (incl. Tracing) 52.74 kB - -
@sentry/browser (incl. Tracing Core) 40.27 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.75 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.63 kB - -
@sentry/browser (incl. Tracing, Replay) 92.79 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.16 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.71 kB - -
@sentry/browser (incl. Feedback) 48.12 kB - -
@sentry/browser (incl. sendFeedback) 30.76 kB - -
@sentry/browser (incl. FeedbackAsync) 35.78 kB - -
@sentry/browser (incl. Metrics) 31.5 kB - -
@sentry/browser (incl. Logs) 31.78 kB - -
@sentry/browser (incl. Metrics & Logs) 32.44 kB - -
@sentry/react 32.19 kB - -
@sentry/react (incl. Tracing) 55.39 kB - -
@sentry/vue 38.38 kB - -
@sentry/vue (incl. Tracing) 55.69 kB - -
@sentry/svelte 30.19 kB - -
@sentry/remix (Remix 3 client bundle) 58.4 kB - -
CDN Bundle 32.11 kB - -
CDN Bundle (incl. Tracing) 53.15 kB - -
CDN Bundle (incl. Logs, Metrics) 34.89 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.71 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.92 kB - -
CDN Bundle (incl. Tracing, Replay) 91.03 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.65 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99 kB - -
CDN Bundle - uncompressed 93.8 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.13 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 102.13 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 164.75 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.25 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 277.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 284.91 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 289.21 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 296.83 kB - -
@sentry/nextjs (client) 59.02 kB - -
@sentry/sveltekit (client) 54.03 kB - -
@sentry/core/server 45.04 kB - -
@sentry/core/browser 14.4 kB - -
@sentry/node 152.12 kB +0.08% +111 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.34 kB - -
@sentry/node - without tracing 88.78 kB +0.13% +107 B 🔺
@sentry/node - without channel injection 141.08 kB +0.1% +133 B 🔺
@sentry/aws-serverless 99.15 kB +0.12% +110 B 🔺
@sentry/cloudflare (withSentry) - minified 206.95 kB - -
@sentry/cloudflare (withSentry) 480.37 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 232.31 kB - -

View base workflow run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ce0dbce. Configure here.

bun.plugin(sentryOrchestrionPlugin());
marker.runtime = [];
debug.log('[Sentry] Registered diagnostics-channel injection via Bun.plugin()');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Init can crash the host app

High Severity

registerBunRuntimeInstrumentation calls Bun.plugin() and constructs the orchestrion transformer with no try/catch. Node’s registerDiagnosticsChannelInjection wraps the same kind of work because an unguarded throw aborts --import/--preload or makes init() throw. A plugin-setup or transformer failure on Bun 1.4.5+ or canary would brick the host instead of degrading to no channel injection.

Additional Locations (2)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit ce0dbce. Configure here.

Comment thread packages/bun/src/sdk.ts
import type { BunOptions } from './types';
import { bunHttpServerIntegration } from './integrations/bunHttpServer';
import { getErrorIntegrations, getTracingIntegrations } from '@sentry/server-utils';
import { registerBunRuntimeInstrumentation } from '@sentry/server-utils/orchestrion/bun';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Runtime pulls in build-time transformer

Medium Severity

@sentry/bun now statically imports @sentry/server-utils/orchestrion/bun, so the orchestrion bundler plugin and its parser stack (meriyah, esquery, astring) load on every SDK import. That happens even on Bun before 1.4.5 and when enableRuntimeChannelInjection is false, where registration is skipped. Node keeps this on @sentry/server-runtime-injection instead of the bundler path. dev-packages/bundler-tests/tests/runtime-entries.test.ts also treats orchestrion/bundler/ as build-time tooling, so @sentry/bun and the new ./import export will fail that test until the runtime hook is split out or the cases are updated.

Additional Locations (2)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit ce0dbce. Configure here.

This branch has not been deployed

No deployments
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