Skip to content

Commit 660a04b

Browse files
authored
fix(telemetry): correct runtime context for Bun binary (#231)
## Summary - Fix incorrect `runtime` tag/context showing `node` instead of `bun` for native Bun binary - Override `client.getOptions().runtime` after `Sentry.init()` to work around `@sentry/bun` v10 bug where `NodeClient` always overrides the runtime option - Keep `cli.runtime` tag for backward compatibility with existing dashboards ## Problem `@sentry/bun` v10 delegates to `@sentry/node`'s `NodeClient`, which always overrides `runtime` to `{ name: 'node', version: process.version }`. Under Bun, `process.version` returns the Node.js compat version (e.g. `v24.3.0`), causing `event.contexts.runtime` and the server-promoted `runtime` tag to incorrectly show `node`. ## Fix Override `client.getOptions().runtime` after `Sentry.init()` with the correct Bun runtime info. `Sentry.setContext()` doesn't work here because `ServerRuntimeClient._prepareEvent()` runs before scope context merging and its result takes precedence. Upstream issue: getsentry/sentry-javascript#19269
1 parent 7c6f815 commit 660a04b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/lib/telemetry.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,27 @@ export function initSentry(enabled: boolean): Sentry.BunClient | undefined {
162162
});
163163

164164
if (client?.getOptions().enabled) {
165-
// Tag whether running as bun binary or node (npm package)
166-
// This is CLI-specific context not provided by the Context integration
167-
const runtime =
168-
typeof process.versions.bun !== "undefined" ? "bun" : "node";
165+
const isBun = typeof process.versions.bun !== "undefined";
166+
const runtime = isBun ? "bun" : "node";
167+
168+
// Fix runtime context: @sentry/bun v10 delegates to @sentry/node's NodeClient,
169+
// which always overrides runtime to { name: 'node', version: process.version }.
170+
// Under Bun, process.version returns the Node.js compat version (e.g. v24.3.0),
171+
// not the Bun version. Override it so event.contexts.runtime is correct and
172+
// Sentry's server-side tag promotion creates an accurate 'runtime' tag.
173+
// TODO: Remove once fixed upstream: https://github.com/getsentry/sentry-javascript/issues/19269
174+
if (isBun) {
175+
// biome-ignore lint/suspicious/noExplicitAny: accessing internal SDK option not exposed in NodeClientOptions
176+
const options = client.getOptions() as any;
177+
options.runtime = {
178+
name: "bun",
179+
version: process.versions.bun as string,
180+
};
181+
}
182+
183+
// Tag whether running as bun binary or node (npm package).
184+
// Kept alongside the SDK's promoted 'runtime' tag for explicit signaling
185+
// and backward compatibility with existing dashboards/alerts.
169186
Sentry.setTag("cli.runtime", runtime);
170187

171188
// Tag whether targeting self-hosted Sentry (not SaaS)

0 commit comments

Comments
 (0)