fix(hono): Return the existing client on repeated init in Bun and Deno - #24520
Conversation
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>
1 similar comment
|
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? |
isaacs
left a comment
There was a problem hiding this comment.
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.
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>
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
withSentryand is not affected.init()returns the existing client. These fail before this change;vitest runfor the hono Bun/Deno/Node tests passes (67 tests).oxfmt --checkpasses on the changed files.oxlintreports the same results as before the change in my environment.Closes #24049
🤖 Generated with Claude Code