Skip to content

ref(hono): move shared Hono instrumentation into @sentry/server-utils - #24496

Open
mydea wants to merge 3 commits into
developfrom
feat/hono-move-to-server-utils
Open

mydea wants to merge 3 commits into
developfrom
feat/hono-move-to-server-utils

Conversation

@mydea

@mydea mydea commented Sep 18, 2026

Copy link
Copy Markdown
Member

First of two stacked PRs splitting the Hono instrumentation rework (originally #24371).

Relocates the runtime-agnostic Hono instrumentation out of @sentry/hono into @sentry/server-utils (src/integrations/hono/), with @sentry/hono re-exporting it. Since @sentry/server-utils must not depend on hono, the relocated code no longer imports it: the Hono class is passed in by the SDK and a vendored honoTypes module provides the shapes. The sentry() middleware now builds its request handler via the shared createHonoRequestMiddleware. Pure relocation — no behavior change.

Also renames the hono-4 e2e test app to hono-4-legacy and moves the corresponding unit tests alongside the relocated code.

The orchestrion-based auto-instrumentation that builds on this lives in the stacked PR #24497.

🤖 Generated with Claude Code

@mydea
mydea added this pull request to stack #24498 September 18, 2026 10:39

@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/wrapMiddlewareSpan.ts
@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.09 kB - -
@sentry/browser - with treeshaking flags 27.35 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.26 kB - -
@sentry/browser (incl. Tracing) 50.56 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 50.58 kB - -
@sentry/browser (incl. Tracing, Profiling) 53.56 kB - -
@sentry/browser (incl. Tracing, Replay) 90.11 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.21 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 94.81 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 107.78 kB - -
@sentry/browser (incl. Feedback) 46.62 kB - -
@sentry/browser (incl. sendFeedback) 34.15 kB - -
@sentry/browser (incl. FeedbackAsync) 39.26 kB - -
@sentry/browser (incl. Metrics) 30.1 kB - -
@sentry/browser (incl. Logs) 30.35 kB - -
@sentry/browser (incl. Metrics & Logs) 31.02 kB - -
@sentry/react 30.84 kB - -
@sentry/react (incl. Tracing) 52.88 kB - -
@sentry/vue 36.34 kB - -
@sentry/vue (incl. Tracing) 52.86 kB - -
@sentry/svelte 29.11 kB - -
CDN Bundle 30.8 kB - -
CDN Bundle (incl. Tracing) 51.1 kB - -
CDN Bundle (incl. Logs, Metrics) 33.06 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.09 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.75 kB - -
CDN Bundle (incl. Tracing, Replay) 88.66 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.58 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 94.7 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.71 kB - -
CDN Bundle - uncompressed 91.16 kB - -
CDN Bundle (incl. Tracing) - uncompressed 152.53 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.73 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 158.49 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.14 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 272.1 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 278.04 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 285.81 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 291.74 kB - -
@sentry/nextjs (client) 55.21 kB - -
@sentry/sveltekit (client) 50.99 kB - -
@sentry/core/server 40 kB - -
@sentry/core/browser 13.66 kB - -
@sentry/node 133.34 kB +0.02% +25 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.17 kB - -
@sentry/node - without tracing 89.93 kB +0.03% +23 B 🔺
@sentry/node - without channel injection 112.15 kB +0.02% +18 B 🔺
@sentry/aws-serverless 98.2 kB +0.03% +21 B 🔺
@sentry/cloudflare (withSentry) - minified 204.74 kB - -
@sentry/cloudflare (withSentry) 509.41 kB - -

View base workflow run

mydea and others added 2 commits September 21, 2026 10:08
Relocate the runtime-agnostic Hono instrumentation out of `@sentry/hono` into
`packages/server-utils/src/integrations/hono/`, with `@sentry/hono` re-exporting
it. Server-utils must not depend on `hono`, so the relocated code no longer
imports it (the `Hono` class is passed in by the SDK and a vendored `honoTypes`
provides the shapes). The `sentry()` middleware now builds its request handler
via the shared `createHonoRequestMiddleware`. No behavior change.

Also renames the `hono-4` e2e test app to `hono-4-legacy` and moves the
corresponding unit tests alongside the relocated code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Align the middleware definitions and assertions in the hono-4-legacy e2e app with
the hono-4 app: anonymous function expressions (name inferred from the const
binding, stable when bundled), a unique per-throw error suffix, and matching error
assertions. Add a named-function middleware case, and a degraded-response test that
documents the manual sentry() middleware does not capture errors thrown solely
inside an internal sub-app .request() (unlike the auto-instrumentation).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mydea
mydea force-pushed the feat/hono-move-to-server-utils branch from 57d3514 to 09ebc47 Compare September 21, 2026 08:13

@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 09ebc47. Configure here.

Comment thread packages/hono/src/cloudflare/middleware.ts Outdated

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

LGTM, only one comment about the deleted tests.

Comment on lines +186 to +197
test.describe('error inside internal fetch (degraded response)', () => {
// The manual `sentry()` middleware only instruments the main app's request lifecycle. An error
// thrown solely inside an internal sub-app `.request()` — whose failed response the outer handler
// swallows — is therefore NOT captured here, unlike the orchestrion auto-instrumentation in the
// `hono-4` app, which instruments every dispatched context. We assert only that the outer request
// stays healthy.
test('degrades to a 200 when the inner route fails', async ({ baseURL }) => {
const response = await fetch(`${baseURL}${STOREFRONT}/product/self-watering-plant/degraded`);
expect(response.status).toBe(200);
await expect(response.json()).resolves.toEqual({ product: null, degraded: true });
});
});

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.

This should be a follow-up fix.

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.

Why was this and wrapMiddlewareSpan deleted?

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.

we'd need to export this from server-utils to be able to test this in the hono package 😢 not 100% sure...

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.

ohhh 😬 then we should at least test this E2E

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.

I added some node-integration tests etc. to cover the things that we used to cover before. I think coverage should be decent now!

The Cloudflare and Deno Hono adapters imported applyHonoPatches, earlyPatchHono
and createHonoRequestMiddleware from the main @sentry/server-utils entry, whose
barrel also loads node:diagnostics_channel and other Node-only modules — which can
fail at import/bundle time on Cloudflare Workers and Deno.

Export the runtime-agnostic helpers from `exports.ts` (shared by both entries),
sourced directly from their modules rather than the ./integrations/hono barrel, so
they are available from @sentry/server-utils/no-diagnostic-channels without pulling
in diagnostics-channel. Point the Cloudflare and Deno adapters at that Node-free
entry. Also move the applyHonoPatches wrapper out of the barrel into the Node-free
applyPatches module.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mydea
mydea marked this pull request as ready for review September 21, 2026 12:43
@mydea
mydea requested review from a team as code owners September 21, 2026 12:43
@mydea
mydea requested review from chargome and nicohrubec and removed request for a team September 21, 2026 12:43

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants