Skip to content

feat(hono)!: Change setup for @sentry/hono/node (init in external file)#20497

Merged
s1gr1d merged 5 commits intodevelopfrom
sig/hono-node-extra
Apr 27, 2026
Merged

feat(hono)!: Change setup for @sentry/hono/node (init in external file)#20497
s1gr1d merged 5 commits intodevelopfrom
sig/hono-node-extra

Conversation

@s1gr1d
Copy link
Copy Markdown
Member

@s1gr1d s1gr1d commented Apr 24, 2026

Let's users set up Sentry in an external file. This makes it easier to filter any integrations. The setup is now slightly different than it is for Bun and Cloudflare, but the Node runtime just works differently.

Closes #20460

BREAKING CHANGE: sentry from @sentry/hono/node does not accept options anymore as those need to be passed in a separate Sentry.init() that is called in an external file:

// instrument.mjs (or instrument.ts)
import * as Sentry from '@sentry/hono/node';

Sentry.init({
  dsn: '__DSN__',
  tracesSampleRate: 1.0,
});

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 26.09 kB - -
@sentry/browser - with treeshaking flags 24.56 kB - -
@sentry/browser (incl. Tracing) 44.04 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 45.7 kB - -
@sentry/browser (incl. Tracing, Profiling) 48.98 kB - -
@sentry/browser (incl. Tracing, Replay) 83.24 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.73 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 87.92 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 100.54 kB - -
@sentry/browser (incl. Feedback) 43.32 kB - -
@sentry/browser (incl. sendFeedback) 30.89 kB - -
@sentry/browser (incl. FeedbackAsync) 36.06 kB - -
@sentry/browser (incl. Metrics) 27.38 kB - -
@sentry/browser (incl. Logs) 27.52 kB - -
@sentry/browser (incl. Metrics & Logs) 28.21 kB - -
@sentry/react 27.83 kB - -
@sentry/react (incl. Tracing) 46.27 kB - -
@sentry/vue 30.95 kB - -
@sentry/vue (incl. Tracing) 45.87 kB - -
@sentry/svelte 26.1 kB - -
CDN Bundle 28.76 kB - -
CDN Bundle (incl. Tracing) 46.27 kB - -
CDN Bundle (incl. Logs, Metrics) 30.16 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 47.32 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 69.12 kB - -
CDN Bundle (incl. Tracing, Replay) 83.31 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 84.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 89.14 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 90.19 kB - -
CDN Bundle - uncompressed 84.36 kB - -
CDN Bundle (incl. Tracing) - uncompressed 138.42 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 88.51 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 141.83 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 212.08 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 255.86 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 259.25 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 269.56 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 272.94 kB - -
@sentry/nextjs (client) 48.77 kB - -
@sentry/sveltekit (client) 44.49 kB - -
@sentry/node-core 58.47 kB +0.02% +10 B 🔺
@sentry/node 169.53 kB +0.01% +13 B 🔺
@sentry/node - without tracing 97.26 kB +0.01% +7 B 🔺
@sentry/aws-serverless 114.01 kB +0.01% +9 B 🔺
@sentry/cloudflare (withSentry) - minified 162.03 kB - -
@sentry/cloudflare (withSentry) 408.94 kB - -

View base workflow run

Comment thread packages/hono/README.md
You won't import `@sentry/node` directly in your code, but it needs to be installed in your project.

### 2. Initialize Sentry in your Hono app
### 2. Initialize Sentry in a separate file
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.

l: maybe just Initialize Sentry?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm, I would rather keep this very explicit

Comment thread packages/hono/README.md Outdated
Read more about this preload script in the docs: https://docs.sentry.io/platforms/javascript/guides/hono/install/late-initialization/#late-initialization-with-esm
### 4. Add the Sentry middleware to your Hono app

Add the `sentry` middleware to your Hono app. Since Sentry was already initialized in the instrument file, no options are needed:
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.

m: if users provide options here again, would that be silently ignored? if that is the case I think it would be good to be a bit more explicit about that people should not use these together

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I added a note/warning about that in the JSDoc to sentry but I can call that out here again. I am wondering if I should just delete the options param...there is no need for really having it.

Comment thread packages/hono/src/node/sdk.ts Outdated
export function init(options: HonoNodeOptions): Client | undefined {
const existingClient = getClient();
if (existingClient) {
debug.log('Sentry is already initialized, skipping re-initialization.');
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.

h: should we also log this outside of debug mode? feels like this would be easy to trip over for users

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 think would be great if we have this generally everywhere 🤔

Comment thread packages/hono/src/node/middleware.ts Outdated
init(options);
export const sentry = (app: Hono, options?: HonoNodeOptions): MiddlewareHandler => {
if (options) {
options.debug && debug.log('Initialized Sentry Hono middleware (Node)');
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.

l: should this be moved to after the init call? since init might still bail

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.

or renaming to Initializing

@s1gr1d s1gr1d changed the title feat(hono): Change setup for @sentry/hono/node (init in external file) feat(hono)!: Change setup for @sentry/hono/node (init in external file) Apr 27, 2026
Copy link
Copy Markdown
Member

@JPeer264 JPeer264 left a comment

Choose a reason for hiding this comment

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

LGTM and everything what Nico wrote

Comment thread packages/hono/src/node/middleware.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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.

Reviewed by Cursor Bugbot for commit ec1df64. Configure here.

if (sentryClient === undefined) {
debug.warn(
'Sentry is not initialized. Call `init()` from @sentry/hono/node in an `instrument.ts` file loaded via `--import` to set up Sentry for your application.',
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning for uninitialized Sentry is silently swallowed

High Severity

The debug.warn() call on the "Sentry is not initialized" path will never produce any output. Internally, debug.warn delegates to _maybeLog, which only logs when both DEBUG_BUILD is true and isEnabled() returns true. The logger is enabled via debug.enable(), which is only called inside initAndBind during Sentry.init(). By definition, when this warning path is reached, init() was never called, so the logger is disabled and the warning is silently swallowed. This is the primary safety net for users who forget the new --import setup step after a breaking change, so it's important that it actually displays. Using consoleSandbox(() => console.warn(...)) instead of debug.warn(...) would work regardless of logger state — this is the same pattern used in initAndBind in packages/core/src/sdk.ts for similar pre-init situations.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ec1df64. Configure here.

@s1gr1d s1gr1d enabled auto-merge (squash) April 27, 2026 09:37
@s1gr1d s1gr1d merged commit b44ff35 into develop Apr 27, 2026
499 of 501 checks passed
@s1gr1d s1gr1d deleted the sig/hono-node-extra branch April 27, 2026 11:27
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.

[Hono] Remove preload-script for Node runtime

3 participants