-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(hono): add orchestrion-based auto-instrumentation #24497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mydea
wants to merge
8
commits into
feat/hono-move-to-server-utils
from
feat/hono-orchestrion-instrumentation
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
75b563c
feat(hono): add orchestrion-based auto-instrumentation
mydea 277348c
fix(hono): capture errors thrown inside internal .request() dispatches
mydea 8529de9
fix(hono): classify matched handlers with isMiddleware before wrapping
mydea 8941894
fix(hono): classify matched handlers by position, not arity alone
mydea 1465586
test(hono): cover deleted unit-test behavior in node-integration tests
mydea 14c7d0d
fix(hono): add captureContextError to the middlewareHandlers test mock
mydea 4862fd6
docs(hono): tighten honoIntegration comments
mydea d7880fd
chore: bump @sentry/node size limit to 136 KB
mydea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
dev-packages/e2e-tests/test-applications/hono-4/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # prod | ||
| dist/ | ||
|
|
||
| # dev | ||
| .yarn/ | ||
| !.yarn/releases | ||
| .vscode/* | ||
| !.vscode/launch.json | ||
| !.vscode/*.code-snippets | ||
| .idea/workspace.xml | ||
| .idea/usage.statistics.xml | ||
| .idea/shelf | ||
|
|
||
| # deps | ||
| node_modules/ | ||
| .wrangler | ||
|
|
||
| # env | ||
| .env | ||
| .env.production | ||
| .dev.vars | ||
|
|
||
| # logs | ||
| logs/ | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| pnpm-debug.log* | ||
| lerna-debug.log* | ||
|
|
||
| # test | ||
| test-results | ||
|
|
||
| # misc | ||
| .DS_Store |
28 changes: 28 additions & 0 deletions
28
dev-packages/e2e-tests/test-applications/hono-4/build-bun.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Builds `src/entry.bun.ts` with the orchestrion `bun build` plugin, emitting `dist/entry.bun.js` | ||
| // for the server to run. The plugin injects the `orchestrion:hono:honoConstructor` diagnostics | ||
| // channel into the bundled `hono`, which the `honoIntegration` default subscribes to. | ||
|
|
||
| // @ts-ignore -- subpath export resolved by Bun at runtime; the package tsconfig's node module | ||
| // resolution can't see `exports` subpaths. | ||
| import { sentryBunPlugin } from '@sentry/bun/plugin'; | ||
| import { join } from 'path'; | ||
|
|
||
| void (async () => { | ||
| const result = await Bun.build({ | ||
| entrypoints: [join(__dirname, 'src/entry.bun.ts')], | ||
| target: 'bun', | ||
| outdir: join(__dirname, 'dist'), | ||
| // `@sentry/bun` (and its deps) stay external, so we don't bundle the whole SDK stack. | ||
| external: ['@sentry/bun'], | ||
| plugins: [sentryBunPlugin()], | ||
| }); | ||
|
|
||
| if (!result.success) { | ||
| // eslint-disable-next-line no-console | ||
| console.error('BUILD_FAILED', result.logs); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // eslint-disable-next-line no-console | ||
| console.log('BUILD_OK'); | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "imports": { | ||
| "@sentry/deno": "npm:@sentry/deno", | ||
| "@sentry/core": "npm:@sentry/core", | ||
| "@opentelemetry/api": "npm:@opentelemetry/api@^1.9.0", | ||
| "hono": "npm:hono@^4.13.1" | ||
| }, | ||
| "nodeModulesDir": "manual" | ||
| } |
57 changes: 57 additions & 0 deletions
57
dev-packages/e2e-tests/test-applications/hono-4/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| { | ||
| "name": "hono-4", | ||
| "type": "module", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev:node": "node --import tsx/esm --import ./src/instrument.node.ts src/entry.node.ts", | ||
| "dev:bun": "bun run dist/entry.bun.js", | ||
| "dev:deno": "deno run --allow-net --allow-env --allow-read --preload=npm:@sentry/deno/import src/entry.deno.ts", | ||
| "dev:cloudflare": "wrangler dev --config ./dist/hono_4/wrangler.json --var \"E2E_TEST_DSN:$E2E_TEST_DSN\" --log-level=$(test $CI && echo 'none' || echo 'log')", | ||
| "test:build": "pnpm install", | ||
| "test": "TEST_ENV=production playwright test", | ||
| "test:assert": "pnpm test:assert:node", | ||
| "test:assert:node": "RUNTIME=node pnpm test", | ||
| "test:assert:bun": "bun run build-bun.ts && RUNTIME=bun pnpm test", | ||
| "test:assert:deno": "RUNTIME=deno pnpm test", | ||
| "test:assert:cloudflare": "vite build && RUNTIME=cloudflare pnpm test" | ||
| }, | ||
| "dependencies": { | ||
| "@sentry/bun": "latest || *", | ||
| "@sentry/cloudflare": "latest || *", | ||
| "@sentry/deno": "latest || *", | ||
| "@sentry/node": "latest || *", | ||
| "@hono/node-server": "^2.0.5", | ||
| "hono": "^4.13.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "~1.63.0", | ||
| "@cloudflare/vite-plugin": "^1.47.0", | ||
| "@cloudflare/workers-types": "^4.20240725.0", | ||
| "@sentry-internal/test-utils": "link:../../../test-utils", | ||
| "tsx": "4.21.0", | ||
| "typescript": "^5.5.2", | ||
| "vite": "^8.1.5", | ||
| "wrangler": "^4.114.0" | ||
| }, | ||
| "volta": { | ||
| "node": "24.15.0", | ||
| "extends": "../../package.json" | ||
| }, | ||
| "sentryTest": { | ||
| "variants": [ | ||
| { | ||
| "assert-command": "pnpm test:assert:bun", | ||
| "label": "hono-4 (bun)" | ||
| }, | ||
| { | ||
| "assert-command": "pnpm test:assert:deno", | ||
| "label": "hono-4 (deno)" | ||
| }, | ||
| { | ||
| "assert-command": "pnpm test:assert:cloudflare", | ||
| "label": "hono-4 (cloudflare)" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
dev-packages/e2e-tests/test-applications/hono-4/playwright.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
| import { RUNTIME, type Runtime } from './tests/constants'; | ||
|
|
||
| const testEnv = process.env.TEST_ENV; | ||
|
|
||
| if (!testEnv) { | ||
| throw new Error('No test env defined'); | ||
| } | ||
|
|
||
| const APP_PORT = 38787; | ||
|
|
||
| const startCommands: Record<Runtime, string> = { | ||
| cloudflare: `pnpm dev:cloudflare --port ${APP_PORT}`, | ||
| node: `pnpm dev:node`, | ||
| bun: `pnpm dev:bun`, | ||
| deno: `pnpm dev:deno`, | ||
| }; | ||
|
|
||
| const config = getPlaywrightConfig( | ||
| { | ||
| startCommand: startCommands[RUNTIME], | ||
| port: APP_PORT, | ||
| }, | ||
| { | ||
| workers: '100%', | ||
| retries: 0, | ||
| }, | ||
| ); | ||
|
|
||
| export default config; |
16 changes: 16 additions & 0 deletions
16
dev-packages/e2e-tests/test-applications/hono-4/src/entry.bun.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Import the Sentry init first so `honoIntegration` is set up (and subscribed to Hono's per-request | ||
| // Context channel) before any request is handled. | ||
| import './instrument.bun'; | ||
| import { Hono } from 'hono'; | ||
| import { addRoutes } from './routes'; | ||
|
|
||
| const app = new Hono(); | ||
|
|
||
| addRoutes(app); | ||
|
|
||
| const port = Number(process.env.PORT || 38787); | ||
|
|
||
| export default { | ||
| port, | ||
| fetch: app.fetch, | ||
| }; |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/hono-4/src/entry.cloudflare.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { Hono } from 'hono'; | ||
| import { addRoutes } from './routes'; | ||
|
|
||
| const app = new Hono<{ Bindings: { E2E_TEST_DSN: string } }>(); | ||
|
|
||
| addRoutes(app); | ||
|
|
||
| export default app; |
13 changes: 13 additions & 0 deletions
13
dev-packages/e2e-tests/test-applications/hono-4/src/entry.deno.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Import the Sentry init first so `honoIntegration` is set up (and subscribed to Hono's per-request | ||
| // Context channel) before any request is handled. | ||
| import './instrument.deno'; | ||
| import { Hono } from 'hono'; | ||
| import { addRoutes } from './routes'; | ||
|
|
||
| const app = new Hono(); | ||
|
|
||
| addRoutes(app); | ||
|
|
||
| const port = Number(Deno.env.get('PORT') || 38787); | ||
|
|
||
| Deno.serve({ port }, app.fetch); |
14 changes: 14 additions & 0 deletions
14
dev-packages/e2e-tests/test-applications/hono-4/src/entry.node.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { serve } from '@hono/node-server'; | ||
| import { Hono } from 'hono'; | ||
| import { addRoutes } from './routes'; | ||
|
|
||
| const app = new Hono(); | ||
|
|
||
| addRoutes(app); | ||
|
|
||
| const port = Number(process.env.PORT || 38787); | ||
|
|
||
| serve({ fetch: app.fetch, port }, () => { | ||
| // eslint-disable-next-line no-console | ||
| console.log(`Hono (Node) listening on port ${port}`); | ||
| }); |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/hono-4/src/instrument.bun.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import * as Sentry from '@sentry/bun'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: process.env.E2E_TEST_DSN, | ||
| environment: 'qa', | ||
| tracesSampleRate: 1.0, | ||
| tunnel: 'http://localhost:3031/', | ||
| }); |
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/hono-4/src/instrument.deno.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import * as Sentry from '@sentry/deno'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: Deno.env.get('E2E_TEST_DSN'), | ||
| environment: 'qa', | ||
| dataCollection: {}, | ||
| tracesSampleRate: 1.0, | ||
| tunnel: 'http://localhost:3031/', | ||
| }); |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/hono-4/src/instrument.node.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: process.env.E2E_TEST_DSN, | ||
| environment: 'qa', | ||
| tracesSampleRate: 1.0, | ||
| tunnel: 'http://localhost:3031/', | ||
| }); |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/hono-4/src/instrument.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Cloudflare-SDK init | ||
| export default (env: { E2E_TEST_DSN: string }) => ({ | ||
| dsn: env.E2E_TEST_DSN, | ||
| environment: 'qa', | ||
| tracesSampleRate: 1.0, | ||
| tunnel: 'http://localhost:3031/', | ||
| }); |
34 changes: 34 additions & 0 deletions
34
dev-packages/e2e-tests/test-applications/hono-4/src/middleware.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { MiddlewareHandler } from 'hono'; | ||
|
|
||
| // Defined as anonymous function expressions so the function name is inferred from the `const` | ||
| // binding. A named expression (`const middlewareA = async function middlewareA() {}`) collides with | ||
| // the binding when bundled, and Bun renames the inner function (→ `middlewareA2`), which would then | ||
| // surface as the middleware span name. The inferred name stays stable across all runtimes. | ||
| export const middlewareA: MiddlewareHandler = async function (c, next) { | ||
| // Add some delay | ||
| await new Promise(resolve => setTimeout(resolve, 50)); | ||
| await next(); | ||
| }; | ||
|
|
||
| export const middlewareB: MiddlewareHandler = async function (_c, next) { | ||
| // Add some delay | ||
| await new Promise(resolve => setTimeout(resolve, 60)); | ||
| await next(); | ||
| }; | ||
|
|
||
| let failingMiddlewareCount = 0; | ||
| export const failingMiddleware: MiddlewareHandler = async function (_c, _next) { | ||
| // Each throw gets a unique suffix so the Dedupe integration doesn't collapse the identical errors | ||
| // that several tests (and their retries) trigger through this shared middleware — otherwise only the | ||
| // first would be reported and the other tests' `waitForError` would time out. Tests match on the | ||
| // stable `Middleware error` prefix. | ||
| throw new Error(`Middleware error #${(failingMiddlewareCount += 1)}`); | ||
| }; | ||
|
|
||
| // Intentionally a NAMED function expression (unlike the anonymous ones above) so the named-function | ||
| // path stays covered: the span name is taken from the function's own name. Under bundled Bun the inner | ||
| // name collides with the `const` binding and is suffixed (→ `namedMiddleware2`), so the test matches on | ||
| // the `namedMiddleware` prefix rather than an exact name. | ||
| export const namedMiddleware: MiddlewareHandler = async function namedMiddleware(_c, next) { | ||
| await next(); | ||
| }; |
45 changes: 45 additions & 0 deletions
45
dev-packages/e2e-tests/test-applications/hono-4/src/route-groups/test-errors.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { Hono } from 'hono'; | ||
| import { HTTPException } from 'hono/http-exception'; | ||
|
|
||
| const errorRoutes = new Hono(); | ||
|
|
||
| // Middleware that throws a 5xx HTTPException (should be captured) | ||
| errorRoutes.use('/middleware-http-exception/*', async (_c, _next) => { | ||
| throw new HTTPException(503, { message: 'Service Unavailable from middleware' }); | ||
| }); | ||
|
|
||
| errorRoutes.get('/middleware-http-exception', c => c.text('should not reach')); | ||
|
|
||
| // Middleware that throws a 4xx HTTPException (should NOT be captured) | ||
| errorRoutes.use('/middleware-http-exception-4xx/*', async (_c, _next) => { | ||
| throw new HTTPException(401, { message: 'Unauthorized from middleware' }); | ||
| }); | ||
|
|
||
| errorRoutes.get('/middleware-http-exception-4xx', c => c.text('should not reach')); | ||
|
|
||
| // Sub-app with a custom onError handler that swallows errors | ||
| const subAppWithOnError = new Hono(); | ||
|
|
||
| subAppWithOnError.onError((err, c) => { | ||
| return c.text(`Handled by onError: ${err.message}`, 500); | ||
| }); | ||
|
|
||
| subAppWithOnError.get('/fail', () => { | ||
| throw new Error('Error caught by custom onError'); | ||
| }); | ||
|
|
||
| errorRoutes.route('/custom-on-error', subAppWithOnError); | ||
|
|
||
| // Nested sub-apps: parent mounts child, child route throws | ||
| const childApp = new Hono(); | ||
|
|
||
| childApp.get('/error', () => { | ||
| throw new Error('Nested child app error'); | ||
| }); | ||
|
|
||
| const parentApp = new Hono(); | ||
| parentApp.route('/child', childApp); | ||
|
|
||
| errorRoutes.route('/nested', parentApp); | ||
|
|
||
| export { errorRoutes }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.