Skip to content

Commit 5166755

Browse files
mydeaclaude
andcommitted
fix(hono): classify matched handlers with isMiddleware before wrapping
The auto-instrumentation injection loop used a raw arity check to decide which matched handlers to wrap as middleware spans. Use the shared isMiddleware helper instead, which unwraps onError-composed sub-app handlers before checking arity — a case the inline check missed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0febd1d commit 5166755

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

packages/server-utils/src/integrations/hono/honoIntegration.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { invokeOrchestrionInstrumentation } from '../../orchestrion/instrumentat
1212
import { bindTracingChannelToSpan, safeChannelCallback } from '../../tracing-channel';
1313
import { applyPatches } from './applyPatches';
1414
import { createHonoRequestMiddleware } from './createHonoMiddleware';
15+
import { isMiddleware } from './isMiddleware';
1516
import { extractPathname, isInternalRequestSpanActive } from './patchAppRequest';
1617
import { wrapMiddlewareWithSpan } from './wrapMiddlewareSpan';
1718
import type { SentryHonoMiddlewareOptions } from './types';
@@ -130,12 +131,13 @@ function injectHonoInstrumentation(
130131
}
131132
_injectedHandlerLists.add(handlers);
132133

133-
// Wrap matched middleware handlers (arity ≥ 2). `wrapMiddlewareWithSpan` is idempotent and skips
134-
// Sentry's own middleware, so this is safe even if a handler is shared across routes.
134+
// Wrap matched middleware handlers. `isMiddleware` also unwraps `onError`-composed sub-app handlers
135+
// before checking, which a raw arity check would miss. `wrapMiddlewareWithSpan` is idempotent and
136+
// skips Sentry's own middleware, so this is safe even if a handler is shared across routes.
135137
for (const entry of handlers) {
136138
const pair = entry?.[0];
137139
const handler = pair?.[0];
138-
if (typeof handler === 'function' && (handler as { length: number }).length >= 2) {
140+
if (isMiddleware(handler)) {
139141
pair[0] = wrapMiddlewareWithSpan(handler as MiddlewareHandler);
140142
}
141143
}

0 commit comments

Comments
 (0)