Skip to content

feat(server-utils): Always warn on Bun when no channel injection is detected - #25857

Open
lazerg wants to merge 6 commits into
getsentry:developfrom
lazerg:fix/bun-no-injection-warning-23882
Open

lazerg wants to merge 6 commits into
getsentry:developfrom
lazerg:fix/bun-no-injection-warning-23882

Conversation

@lazerg

@lazerg lazerg commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Why: Under bun run there is no Module.registerHooks, so the runtime injection never registers and the channel integrations stay silent, including their error capture. The only hint was a debug.warn, so on Bun this is now an always-on consoleSandbox warning that points to @sentry/bun/plugin. Node keeps the debug-only message.

Closes #23882

…etected

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the external PR from an external contributor label Oct 29, 2026
@lazerg
lazerg marked this pull request as ready for review October 29, 2026 07:05
@lazerg
lazerg requested a review from a team as a code owner October 29, 2026 07:05
@lazerg
lazerg requested review from andreiborza and isaacs and removed request for a team October 29, 2026 07:05

@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 1 potential issue.

Fix All in Cursor

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

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d609f13. Configure here.

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

@Lms24 Lms24 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I will leave the final call up to @isaacs around the PR but wanted to share a thought: We should be careful when we log to the console without the debug gate. Not sure if this could trickle down to end users who suddenly get Sentry output in their console.

Have we considered adjusting the warning message like in this PR but keeping the debug gate?

@lazerg

lazerg commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Fair concern, but making it visible without debug is the point of #23882: on Bun under bun run the channel integrations (including error capture) silently never fire, and users don't know to turn on debug. I limited it to Bun only and kept Node debug-gated, but I'm happy to follow whatever you and isaacs decide.

…talled

The Bun warning for missing channel injection showed even when no
integration uses the channels, for example with
`initWithoutDefaultIntegrations()` or `defaultIntegrations: false`. In
those setups nothing is lost, the message is false, and the user has
no way to turn it off.

Every integration that needs channel injection subscribes through
`invokeOrchestrionInstrumentation()`. The helper now sets
`channelIntegrations` on the orchestrion marker, and
`detectOrchestrionSetup()` shows the Bun warning only when that flag is
set. This needs no list of integration names to keep in sync.
Integrations that do not need injection, such as Fastify, do not call
the helper and do not set the flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@isaacs
isaacs requested review from a team as code owners November 5, 2026 01:04
@isaacs
isaacs requested review from Lms24, chargome, logaretm and s1gr1d and removed request for a team November 5, 2026 01:04
isaacs and others added 2 commits November 4, 2026 17:06
…tion warning

The Bun warning fires whenever no injection marker exists, not only
under `bun run`. A `bun build --compile` binary or a `Bun.build` bundle
made without `@sentry/bun/plugin` gets the same warning, and the advice
to build with the plugin is right for those too. Only the `bun run`
phrase was wrong, so the message now gives the real cause: Bun cannot
instrument modules at runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Node's `_init` still replaces the client on a repeated `Sentry.init()`,
and it calls `detectOrchestrionSetup()` each time. The Bun warning is
always on, so a second `init()` showed it again.

The warning now sets `warnedBunRunNotInjected` on the orchestrion
marker and does not show again while it is set. The flag lives on the
marker, not in module state, so duplicate SDK copies in one process
also warn only once.

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

isaacs commented Nov 5, 2026

Copy link
Copy Markdown
Member

This is the smallest patch which could solve the problem, which is always the best place to start :)

Re the concern @Lms24 raises, and @lazerg's response, I actually think you're both right. We do need the warning to print for bun run users outside of debug mode. However, the way it's written here, it could print in some cases where it's not warranted, for example if someone isn't using any instrumentations that depend on module diagnostic channel injections.

I added a flag to the orchestrion marker, so that on bun we can know for certain if the user is in that state where the warning would be applicable, instead of just inferring it from their platform. With that change, I think this is ready to land, so I'll get that landed as soon as CI is complete.

@isaacs
isaacs enabled auto-merge (squash) November 5, 2026 01:22
@lazerg

lazerg commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, checking the marker flag is much better than guessing from the platform. One heads-up: the Bun integration jobs on 8e27791 fail because the warning now prints in esm/modules-integration and orchestrion-registration-only, and both expect no error output.

…output checks

The Bun integration jobs run the Node suites with `bun run` and without
`@sentry/bun/plugin`, so the SDK now warns on stderr that channel
injection is missing. `ensureNoErrorOutput()` failed on that warning in
`esm/modules-integration` and `tracing/orchestrion-registration-only`.

When `RUNTIME` is `bun`, the runner now drops that warning line before
it checks stderr. Other output on the same chunk still fails the test.

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

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

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bun: Channel injection is unavailable under bun run, and only a debug log says so

3 participants