Skip to content

Commit 872d161

Browse files
committed
update tests
1 parent d8f3188 commit 872d161

10 files changed

Lines changed: 171 additions & 12 deletions

File tree

dev-packages/cloudflare-integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"@langchain/langgraph": "^1.0.1",
1717
"@sentry/cloudflare": "10.36.0",
18+
"@sentry/hono": "10.36.0",
1819
"hono": "^4.0.0"
1920
},
2021
"devDependencies": {

dev-packages/cloudflare-integration-tests/suites/hono-integration/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ app.get('/json', c => {
1616
});
1717

1818
app.get('/error', () => {
19-
throw new Error('Test error from Hono app');
19+
throw new Error('Test error from Hono app (Sentry Cloudflare SDK)');
2020
});
2121

2222
app.get('/hello/:name', c => {

dev-packages/cloudflare-integration-tests/suites/hono-integration/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, it } from 'vitest';
2-
import { eventEnvelope } from '../../../expect';
3-
import { createRunner } from '../../../runner';
2+
import { eventEnvelope } from '../../expect';
3+
import { createRunner } from '../../runner';
44

55
it('Hono app captures errors', async ({ signal }) => {
66
const runner = createRunner(__dirname)
@@ -14,7 +14,7 @@ it('Hono app captures errors', async ({ signal }) => {
1414
values: [
1515
{
1616
type: 'Error',
17-
value: 'Test error from Hono app',
17+
value: 'Test error from Hono app (Sentry Cloudflare SDK)',
1818
stacktrace: {
1919
frames: expect.any(Array),
2020
},
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { sentry } from '@sentry/hono/cloudflare-workers';
2+
import { Hono } from 'hono';
3+
4+
interface Env {
5+
SENTRY_DSN: string;
6+
}
7+
8+
const app = new Hono<{ Bindings: Env }>();
9+
10+
app.use(
11+
'*',
12+
sentry(app, {
13+
dsn: process.env.SENTRY_DSN,
14+
tracesSampleRate: 1.0,
15+
debug: true,
16+
// todo - what is going on with this
17+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
18+
// @ts-ignore
19+
integrations: integrations => integrations.filter(integration => integration.name !== 'Hono'),
20+
}),
21+
);
22+
23+
app.get('/', c => {
24+
return c.text('Hello from Hono on Cloudflare!');
25+
});
26+
27+
app.get('/json', c => {
28+
return c.json({ message: 'Hello from Hono', framework: 'hono', platform: 'cloudflare' });
29+
});
30+
31+
app.get('/error', () => {
32+
throw new Error('Test error from Hono app');
33+
});
34+
35+
app.get('/hello/:name', c => {
36+
const name = c.req.param('name');
37+
return c.text(`Hello, ${name}!`);
38+
});
39+
40+
export default app;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { SDK_VERSION } from '@sentry/core';
2+
import { expect, it } from 'vitest';
3+
import { SHORT_UUID_MATCHER, UUID_MATCHER } from '../../expect';
4+
import { createRunner } from '../../runner';
5+
6+
it('Hono app captures errors (Hono SDK)', async ({ signal }) => {
7+
const runner = createRunner(__dirname)
8+
.expect(envelope => {
9+
const [, envelopeItems] = envelope;
10+
const [itemHeader, itemPayload] = envelopeItems[0];
11+
12+
expect(itemHeader.type).toBe('event');
13+
14+
// todo: check with function eventEnvelope
15+
16+
// Validate error event structure
17+
expect(itemPayload).toMatchObject({
18+
level: 'error',
19+
platform: 'javascript',
20+
transaction: 'GET /error',
21+
// fixme: should be hono
22+
sdk: { name: 'sentry.javascript.cloudflare', version: SDK_VERSION },
23+
// fixme: should contain trace
24+
// trace: expect.objectContaining({ trace_id: UUID_MATCHER }),
25+
exception: {
26+
values: expect.arrayContaining([
27+
expect.objectContaining({
28+
type: 'Error',
29+
value: 'Test error from Hono app',
30+
mechanism: expect.objectContaining({
31+
type: 'generic', // fixme: should be 'auto.faas.hono.error_handler'
32+
handled: true, // fixme: should be false
33+
}),
34+
}),
35+
]),
36+
},
37+
request: expect.objectContaining({
38+
method: 'GET',
39+
url: expect.stringContaining('/error'),
40+
}),
41+
});
42+
})
43+
.expect(envelope => {
44+
const [, envelopeItems] = envelope;
45+
const [itemHeader, itemPayload] = envelopeItems[0];
46+
47+
expect(itemHeader.type).toBe('transaction');
48+
49+
expect(itemPayload).toMatchObject({
50+
type: 'transaction',
51+
platform: 'javascript',
52+
transaction: 'GET /error',
53+
contexts: {
54+
trace: {
55+
span_id: expect.any(String),
56+
trace_id: expect.any(String),
57+
op: 'http.server',
58+
status: 'internal_error',
59+
origin: 'auto.http.cloudflare',
60+
},
61+
},
62+
request: expect.objectContaining({
63+
method: 'GET',
64+
url: expect.stringContaining('/error'),
65+
}),
66+
});
67+
})
68+
69+
.unordered()
70+
.start(signal);
71+
72+
await runner.makeRequest('get', '/error', { expectError: true });
73+
await runner.completed();
74+
});
75+
76+
it('Hono app captures parametrized names', async ({ signal }) => {
77+
const runner = createRunner(__dirname)
78+
.expect(envelope => {
79+
const [, envelopeItems] = envelope;
80+
const [itemHeader, itemPayload] = envelopeItems[0];
81+
82+
expect(itemHeader.type).toBe('transaction');
83+
84+
expect(itemPayload).toMatchObject({
85+
type: 'transaction',
86+
platform: 'javascript',
87+
transaction: 'GET /hello/:name',
88+
contexts: {
89+
trace: {
90+
span_id: SHORT_UUID_MATCHER,
91+
trace_id: UUID_MATCHER,
92+
op: 'http.server',
93+
status: 'ok',
94+
origin: 'auto.http.cloudflare',
95+
},
96+
},
97+
request: expect.objectContaining({
98+
method: 'GET',
99+
url: expect.stringContaining('/hello/:name'),
100+
}),
101+
});
102+
})
103+
104+
.unordered()
105+
.start(signal);
106+
107+
await runner.makeRequest('get', '/hello/:name', { expectError: false });
108+
await runner.completed();
109+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "hono-sdk-worker",
3+
"compatibility_date": "2025-06-17",
4+
"main": "index.ts",
5+
"compatibility_flags": ["nodejs_compat"]
6+
}
7+

dev-packages/cloudflare-integration-tests/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// global fetch available in tests in lower Node versions.
99
"lib": ["ES2020"],
1010
"esModuleInterop": true,
11-
"types": ["@cloudflare/workers-types"]
11+
"types": ["@cloudflare/workers-types"],
12+
"moduleResolution": "bundler"
1213
}
1314
}

packages/hono/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sentry/hono",
3-
"version": "10.32.1",
3+
"version": "10.33.0",
44
"description": "Official Sentry SDK for Hono (ALPHA)",
55
"repository": "git://github.com/getsentry/sentry-javascript.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/hono",
@@ -53,9 +53,9 @@
5353
},
5454
"dependencies": {
5555
"@opentelemetry/api": "^1.9.0",
56-
"@sentry/cloudflare": "^10.32.1",
57-
"@sentry/core": "10.32.1",
58-
"@sentry/node": "10.32.1"
56+
"@sentry/cloudflare": "10.33.0",
57+
"@sentry/core": "10.33.0",
58+
"@sentry/node": "10.33.0"
5959
},
6060
"peerDependencies": {
6161
"@cloudflare/workers-types": "^4.x",

packages/hono/src/shared/middlewareHandlers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
winterCGRequestToRequestData,
99
} from '@sentry/core';
1010
import type { Context } from 'hono';
11-
import { routePath } from 'hono/dist/types/helper/route/index';
11+
import { routePath } from 'hono/route';
1212
import { hasFetchEvent } from '../utils/hono-context';
1313

1414
/**
15-
*
15+
* todo
1616
*/
1717
export function requestHandler(context: Context): void {
1818
const defaultScope = getDefaultIsolationScope();
@@ -26,7 +26,7 @@ export function requestHandler(context: Context): void {
2626
}
2727

2828
/**
29-
*
29+
* todo
3030
*/
3131
export function responseHandler(context: Context): void {
3232
const activeSpan = getActiveSpan();

packages/hono/src/utils/hono-context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Context } from 'hono';
2+
23
/**
34
* Checks whether the given Hono context has a fetch event.
45
*/

0 commit comments

Comments
 (0)