Skip to content

feat(hono): Add hono.request spans for internal .request() calls#20843

Open
s1gr1d wants to merge 4 commits into
developfrom
sig/hono-connected-multi-fetches
Open

feat(hono): Add hono.request spans for internal .request() calls#20843
s1gr1d wants to merge 4 commits into
developfrom
sig/hono-connected-multi-fetches

Conversation

@s1gr1d
Copy link
Copy Markdown
Member

@s1gr1d s1gr1d commented May 12, 2026

Hono apps commonly use sub-apps and fetch data between them via .request(), but these internal calls were invisible in traces. This PR adds hono.request child spans so users can see the full picture when one Hono app calls another internally (single, parallel, or sequential calls).

Also restructures the route hook into two-phases: sub-app references are collected at import time and instrumented when sentry() activates. This ensures sub-apps mounted before sentry() is registered aren't silently missed (without generating any spans or overhead if Sentry is never initialized).

Step-by-step description:

  1. When the user imports @sentry/hono, earlyPatchHono() runs at module load time and hooks HonoBase.prototype.route. Any sub-app passed to .route() from this point on is collected into a pending set (but not yet instrumented).
  2. The user creates their Hono app and mounts sub-apps via app.route('/prefix', subApp). Sub-apps are silently collected by the hook.
  3. The user registers app.use(sentry()), which calls applyPatches(app).
  4. applyPatches patches app.use on the main app instance (via Proxy) so all future middleware registrations are wrapped in spans.
  5. applyPatches patches app.request on the main app instance so internal .request() calls (for fetches) are traced as hono.request spans.
  6. The route hook is activated. Any sub-app mounted via .route() from now on is instrumented immediately at mount time.
  7. All sub-apps collected in the pending set (mounted before sentry()) are drained and retroactively instrumented: their middleware is wrapped in spans and their .request() is patched.

Closes #20807

@s1gr1d s1gr1d requested a review from a team as a code owner May 12, 2026 15:20
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2026

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 26.88 kB - -
@sentry/browser - with treeshaking flags 25.32 kB - -
@sentry/browser (incl. Tracing) 44.78 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 46.75 kB - -
@sentry/browser (incl. Tracing, Profiling) 49.77 kB - -
@sentry/browser (incl. Tracing, Replay) 84.41 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 73.84 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.11 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 101.75 kB - -
@sentry/browser (incl. Feedback) 44.06 kB - -
@sentry/browser (incl. sendFeedback) 31.69 kB - -
@sentry/browser (incl. FeedbackAsync) 36.8 kB - -
@sentry/browser (incl. Metrics) 27.97 kB - -
@sentry/browser (incl. Logs) 28.11 kB - -
@sentry/browser (incl. Metrics & Logs) 28.8 kB - -
@sentry/react 28.63 kB - -
@sentry/react (incl. Tracing) 47.05 kB - -
@sentry/vue 31.8 kB - -
@sentry/vue (incl. Tracing) 46.65 kB - -
@sentry/svelte 26.9 kB - -
CDN Bundle 29.26 kB - -
CDN Bundle (incl. Tracing) 47.17 kB - -
CDN Bundle (incl. Logs, Metrics) 30.64 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 48.29 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 69.97 kB - -
CDN Bundle (incl. Tracing, Replay) 84.56 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.63 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 90.37 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 91.47 kB - -
CDN Bundle - uncompressed 86.08 kB - -
CDN Bundle (incl. Tracing) - uncompressed 141.53 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 90.28 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 145 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 215.1 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 260.24 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 263.69 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 273.94 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 277.38 kB - -
@sentry/nextjs (client) 49.56 kB - -
@sentry/sveltekit (client) 45.27 kB - -
@sentry/node-core 60.84 kB +0.02% +10 B 🔺
@sentry/node 165.98 kB +0.01% +9 B 🔺
@sentry/node - without tracing 73.97 kB +0.01% +7 B 🔺
@sentry/aws-serverless 108.07 kB +0.01% +7 B 🔺
@sentry/cloudflare (withSentry) - minified 170.68 kB - -
@sentry/cloudflare (withSentry) 430.48 kB - -

View base workflow run

Comment thread packages/hono/src/shared/patchAppRequest.ts Outdated
@chargome chargome self-requested a review May 13, 2026 14:10
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] Instrument multi-fetch apps with internal .request

1 participant