Skip to content

fix(hono): Return the existing client on repeated init in Bun and Deno - #24520

Merged
isaacs merged 1 commit into
getsentry:developfrom
Shubham-Padkonde:fix/hono-bun-deno-double-init
Oct 1, 2026
Merged

isaacs merged 1 commit into
getsentry:developfrom
Shubham-Padkonde:fix/hono-bun-deno-double-init

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown
Contributor

On Bun and Deno, init() warned when Sentry was already initialized but then initialized again, replacing the client. Anything buffered on the first client was dropped and its integrations stayed installed against it.

Both now keep the warning and return the existing client, as the Node entry already does. Node's behavior is unchanged (it only logs in debug mode, since it is initialized from an instrument file); Cloudflare initializes per request through withSentry and is not affected.

  • Tests: the Bun and Deno double-init tests now expect no re-initialization, plus a test that init() returns the existing client. These fail before this change; vitest run for the hono Bun/Deno/Node tests passes (67 tests).
  • oxfmt --check passes on the changed files. oxlint reports the same results as before the change in my environment.

Closes #24049

🤖 Generated with Claude Code

On Bun and Deno, init() warned when Sentry was already initialized but
then initialized again, replacing the client. Anything buffered on the
first client was dropped and its integrations stayed installed against it.
Keep the warning and return the existing client, as the Node entry does.

Fixes getsentry#24049

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Shubham-Padkonde
Shubham-Padkonde requested a review from a team as a code owner September 19, 2026 09:30
@Shubham-Padkonde
Shubham-Padkonde requested review from mydea and s1gr1d and removed request for a team September 19, 2026 09:30
@github-actions

Copy link
Copy Markdown
Contributor

👋 @mydea, @s1gr1d — Please review this PR when you get a chance!

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

👋 @mydea, @s1gr1d — Please review this PR when you get a chance!

@mydea
mydea requested a review from isaacs September 29, 2026 11:16
@mydea

mydea commented Sep 29, 2026

Copy link
Copy Markdown
Member

Can you elaborate on what motivated this change? E.g. ideally you'd just avoid calling init multiple times in the first place, how would you get to a point where you call this more often?

@s1gr1d s1gr1d added the external PR from an external contributor label Sep 29, 2026

@isaacs isaacs 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.

While it's not a great idea to call Sentry.init() multiple times, as @mydea pointed out, and usually indicative of a mistake, what we have now in the codebase is a bit of a mess of undefined and inconsistent behavior.

This PR doesn't address all of the cases of this inconsistency, but it did help to highlight the issue and raise it to our attention. So thank you for that!

Initially, we were unsure whether it made the most sense to bring Bun and Deno into alignment with Node here, or the other way around. But a rigorous survey of the various JS SDKs does show that this is the correct path, and is a good initial fix to get us into alignment with a consistent rule: "The first init() wins. A repeated call changes nothing, returns the active client, and says so."

It's a much larger project to bring all the current JS SDKs into alignment with this idea, and requires a bit of care to ensure we do so in a strictly nonbreaking way. We just had a discussion about this within the team. I'm going to land this PR, and then set about creating issues and PRs to get the rest fixed.

@isaacs
isaacs merged commit c1e182c into getsentry:develop Oct 1, 2026
49 checks passed
nicohrubec pushed a commit that referenced this pull request Oct 1, 2026
This PR adds the external contributor to the CHANGELOG.md file, so that
they are credited for their contribution. See #24520

Co-authored-by: isaacs <9287+isaacs@users.noreply.github.com>
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.

hono: Double init() behaves differently per runtime

4 participants