Skip to content

feat(hono): Instrument main-app inline middleware spans#20999

Merged
s1gr1d merged 4 commits into
developfrom
sig/hono-inline-middleware
May 26, 2026
Merged

feat(hono): Instrument main-app inline middleware spans#20999
s1gr1d merged 4 commits into
developfrom
sig/hono-inline-middleware

Conversation

@s1gr1d
Copy link
Copy Markdown
Member

@s1gr1d s1gr1d commented May 19, 2026

The Hono SDK already instruments .use (for middleware) but not yet the HTTP method inline middleware.
See more here: https://hono.dev/docs/guides/middleware#definition-of-middleware

This PR also adds some additional test cases for existing tests to make the tests more robust.

image

@s1gr1d s1gr1d requested a review from a team as a code owner May 19, 2026 10:17
@s1gr1d s1gr1d force-pushed the sig/hono-inline-middleware branch from 0dad338 to 32b0390 Compare May 19, 2026 10:28
Copy link
Copy Markdown
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

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

Nice!

*/
export function patchHttpMethodHandlers<E extends Env>(app: Hono<E>): void {
for (const method of HTTP_METHODS) {
app[method] = new Proxy(app[method], {
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: For patchAppUse you prevented double wrapping with a check at this point

Copy link
Copy Markdown
Member Author

@s1gr1d s1gr1d May 26, 2026

Choose a reason for hiding this comment

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

We check for double wrapping in wrapMiddlewareWithSpan in line 24. The function is called by patchHttpMethodHandlers. But I'll add a test so we can be sure it produces only one span.

But for tidiness it's probably worth monitoring what was already patched, so we don't accumulate multiple proxy layers (even though those would still just create one span).

@s1gr1d s1gr1d force-pushed the sig/hono-inline-middleware branch from 32b0390 to c58a52f Compare May 26, 2026 12:28
@s1gr1d s1gr1d enabled auto-merge (squash) May 26, 2026 12:28
Comment thread packages/hono/src/shared/patchAppUse.ts
@s1gr1d s1gr1d merged commit 46be544 into develop May 26, 2026
71 of 75 checks passed
@s1gr1d s1gr1d deleted the sig/hono-inline-middleware branch May 26, 2026 13:34
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