Skip to content

feat(hono): Auto-instrument Hono via @sentry/server-utils + orchestrion - #24371

Draft
mydea wants to merge 18 commits into
developfrom
feat/hono-server-utils-integration
Draft

mydea wants to merge 18 commits into
developfrom
feat/hono-server-utils-integration

Conversation

@mydea

@mydea mydea commented Sep 14, 2026

Copy link
Copy Markdown
Member

Summary

Moves the Hono instrumentation into @sentry/server-utils and drives it through orchestrion, so Hono is auto-instrumented out of the box by @sentry/node, @sentry/bun, @sentry/deno, and @sentry/cloudflare — no @sentry/hono import and no manual sentry() middleware required.

@sentry/hono keeps working exactly as before: it now re-uses the shared code from @sentry/server-utils instead of owning its own copy.

How it works

  • The runtime-agnostic Hono instrumentation (route/middleware span patches, request/response handlers, transaction naming, context-error capture) moved from @sentry/hono/src/shared to @sentry/server-utils/src/integrations/hono.
  • A new honoIntegration (default in the server SDKs' getErrorIntegrations()) hooks the Hono constructor via an orchestrion diagnostics channel (orchestrion:hono:honoConstructor) and, on every new app, registers the Sentry request/response middleware first and applies the span patches.
  • @sentry/server-utils takes no dependency on hono — not at runtime (the Hono prototype is derived from the live app instance; matched routes are read from the request's own getters instead of hono/route) and not at build/type time (the needed types are vendored in honoTypes.ts).

Per-runtime enablement

Duplicate handling

Request handling is deduplicated per request via the isolation scope, so all of these run the Sentry logic exactly once:

  • a manual sentry() middleware alongside the auto-instrumentation,
  • mounted sub-apps that carry their own auto-registered middleware,
  • internal app.request() dispatches (a new Hono context, same isolation scope).

A user-provided shouldHandleError still wins even when its middleware is deduplicated behind the auto-instrumentation.

Tests

  • Unit (@sentry/server-utils): isMiddleware, defaultShouldHandleError, and the dedup logic in createHonoMiddleware.
  • node-integration-tests (suites/hono): auto-instrumentation with plain @sentry/node (ESM + CJS) — transaction naming, error capture/mechanism, plus regression cases for mounted sub-apps (no stray <anonymous> middleware span) and internal .request() (no span rename / request-data pollution).
  • node-mastra: asserts the http.server span (method/route/url) for Mastra's Hono-served agent endpoint.
  • e2e: new native hono-4 app exercising node/bun/deno/cloudflare via the runtime SDKs directly; the previous @sentry/hono-based app is preserved as hono-4-legacy.
  • e2e runner: added per-variant skip support (getTestMatrix.mjs + run.ts).

Known limitations / follow-ups

  • Deno auto-instrumentation is currently blocked upstream. On Deno's sync Module.registerHooks path, @apm-js-collab/tracing-hooks derives the module type only from result.format, which Deno doesn't report as 'module' for Hono's ESM build — so a CJS require() is injected into an ES module (ReferenceError: require is not defined). Filed as Sync hooks path injects CommonJS require() into ESM modules on Deno → ReferenceError: require is not defined apm-js-collab/tracing-hooks#53. The hono-4 deno variant is marked skip until it lands. (Node works because it uses the async Module.register path, which reports the format correctly.)
  • @sentry/hono remains as-is (thin re-export layer); no deprecation for now.

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

Stale Bugbot comment from a previous run.

Comment thread packages/server-utils/src/integrations/hono/applyPatches.ts
Comment thread packages/server-utils/src/integrations/hono/index.ts
Comment thread packages/server-utils/src/integrations/index.ts
Comment thread packages/server-utils/src/integrations/hono/createHonoMiddleware.ts Outdated
@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.96 kB - -
@sentry/browser - with treeshaking flags 27.26 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.15 kB - -
@sentry/browser (incl. Tracing) 50.51 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 50.52 kB - -
@sentry/browser (incl. Tracing, Profiling) 53.5 kB - -
@sentry/browser (incl. Tracing, Replay) 90.07 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.16 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 94.77 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 107.73 kB - -
@sentry/browser (incl. Feedback) 46.46 kB - -
@sentry/browser (incl. sendFeedback) 34.01 kB - -
@sentry/browser (incl. FeedbackAsync) 39.12 kB - -
@sentry/browser (incl. Metrics) 29.98 kB - -
@sentry/browser (incl. Logs) 30.24 kB - -
@sentry/browser (incl. Metrics & Logs) 30.91 kB - -
@sentry/react 30.72 kB - -
@sentry/react (incl. Tracing) 52.81 kB - -
@sentry/vue 36.2 kB - -
@sentry/vue (incl. Tracing) 52.76 kB - -
@sentry/svelte 28.98 kB - -
CDN Bundle 30.7 kB - -
CDN Bundle (incl. Tracing) 51.01 kB - -
CDN Bundle (incl. Logs, Metrics) 32.98 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 52.99 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.67 kB - -
CDN Bundle (incl. Tracing, Replay) 88.56 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.53 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 94.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.63 kB - -
CDN Bundle - uncompressed 90.83 kB - -
CDN Bundle (incl. Tracing) - uncompressed 152.33 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.41 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 158.29 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 226.82 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 271.9 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 277.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 285.6 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 291.54 kB - -
@sentry/nextjs (client) 55.13 kB - -
@sentry/sveltekit (client) 50.93 kB - -
@sentry/core/server 37.13 kB - -
@sentry/core/browser 13.66 kB - -
@sentry/node 133.1 kB +1.89% +2.46 kB 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.93 kB +0.06% +42 B 🔺
@sentry/node - without tracing 91.91 kB +2.5% +2.24 kB 🔺
@sentry/node - without channel injection 111.93 kB +2.18% +2.39 kB 🔺
@sentry/aws-serverless 100.17 kB +2.32% +2.27 kB 🔺
@sentry/cloudflare (withSentry) - minified 203.36 kB - -
@sentry/cloudflare (withSentry) 506.44 kB - -

View base workflow run

@mydea
mydea force-pushed the feat/hono-server-utils-integration branch from 7b5f046 to 1e9f2bd Compare September 14, 2026 14:40

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

Stale Bugbot comment from a previous run.

Comment thread dev-packages/e2e-tests/test-applications/hono-4/package.json
Comment thread dev-packages/e2e-tests/test-applications/hono-4/package.json Outdated
Comment thread packages/server-utils/src/integrations/hono/honoIntegration.ts

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

Stale Bugbot comment from a previous run.

Comment thread .github/workflows/build.yml Outdated
Comment thread packages/server-utils/src/integrations/hono/patchAppRequest.ts
@mydea mydea changed the title WIP hono integration feat(hono): Auto-instrument Hono via @sentry/server-utils + orchestrion Sep 15, 2026
@mydea
mydea force-pushed the feat/hono-server-utils-integration branch from 2b018b4 to 5af594d Compare September 15, 2026 07:54

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

Reviewed by Cursor Bugbot for commit 5af594d. Configure here.

Comment thread dev-packages/e2e-tests/test-applications/hono-4/package.json
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.

1 participant