Skip to content

Commit 587213d

Browse files
cursoragentclaude
andcommitted
fix(hono): use node mechanism type in node middleware
Co-Authored-By: gpt-5.3-codex-high <noreply@anthropic.com>
1 parent 377c5cf commit 587213d

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

packages/hono/src/node/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export const sentry = (app: Hono, options: HonoOptions | undefined = {}): Middle
2727

2828
await next(); // Handler runs in between Request above ⤴ and Response below ⤵
2929

30-
responseHandler(context);
30+
responseHandler(context, 'auto.middleware.hono.error_handler');
3131
};
3232
};

packages/hono/src/shared/middlewareHandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function requestHandler(context: Context): void {
2929
/**
3030
* Response handler for Hono framework
3131
*/
32-
export function responseHandler(context: Context): void {
32+
export function responseHandler(context: Context, mechanismType = 'auto.faas.hono.error_handler'): void {
3333
const activeSpan = getActiveSpan();
3434
if (activeSpan) {
3535
activeSpan.updateName(`${context.req.method} ${routePath(context)}`);
@@ -44,7 +44,7 @@ export function responseHandler(context: Context): void {
4444

4545
if (context.error) {
4646
getClient()?.captureException(context.error, {
47-
mechanism: { handled: false, type: 'auto.faas.hono.error_handler' },
47+
mechanism: { handled: false, type: mechanismType },
4848
});
4949
}
5050
}

packages/hono/test/vercel/middleware.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import * as SentryCore from '@sentry/core';
22
import { SDK_VERSION } from '@sentry/core';
33
import { Hono } from 'hono';
44
import { beforeEach, describe, expect, it, type Mock, vi } from 'vitest';
5+
import * as middlewareHandlers from '../../src/shared/middlewareHandlers';
56
import { sentry } from '../../src/node/middleware';
67

78
vi.mock('@sentry/node', () => ({
89
init: vi.fn(),
910
}));
1011

12+
vi.mock('../../src/shared/middlewareHandlers', () => ({
13+
requestHandler: vi.fn(),
14+
responseHandler: vi.fn(),
15+
}));
16+
1117
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
1218
const { init: initNodeMock } = await vi.importMock<typeof import('@sentry/node')>('@sentry/node');
1319

@@ -22,6 +28,8 @@ vi.mock('@sentry/core', async () => {
2228
});
2329

2430
const applySdkMetadataMock = SentryCore.applySdkMetadata as Mock;
31+
const requestHandlerMock = middlewareHandlers.requestHandler as Mock;
32+
const responseHandlerMock = middlewareHandlers.responseHandler as Mock;
2533

2634
describe('Hono Vercel Middleware', () => {
2735
beforeEach(() => {
@@ -114,6 +122,18 @@ describe('Hono Vercel Middleware', () => {
114122
expect(middleware.constructor.name).toBe('AsyncFunction');
115123
});
116124

125+
it('uses node mechanism type for response errors', async () => {
126+
const app = new Hono();
127+
const middleware = sentry(app, {});
128+
const context = {} as Parameters<typeof middleware>[0];
129+
const next = vi.fn(async () => undefined);
130+
131+
await middleware(context, next);
132+
133+
expect(requestHandlerMock).toHaveBeenCalledWith(context);
134+
expect(responseHandlerMock).toHaveBeenCalledWith(context, 'auto.middleware.hono.error_handler');
135+
});
136+
117137
it('includes hono SDK metadata', () => {
118138
const app = new Hono();
119139
const options = {

0 commit comments

Comments
 (0)