Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-packages/cloudflare-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@langchain/langgraph": "^1.0.1",
"@sentry/cloudflare": "10.33.0",
"@sentry/hono": "10.33.0",
"hono": "^4.0.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ app.get('/json', c => {
});

app.get('/error', () => {
throw new Error('Test error from Hono app');
throw new Error('Test error from Hono app (Sentry Cloudflare SDK)');
});

app.get('/hello/:name', c => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, it } from 'vitest';
import { eventEnvelope } from '../../../expect';
import { createRunner } from '../../../runner';
import { eventEnvelope } from '../../expect';
import { createRunner } from '../../runner';

it('Hono app captures errors', async ({ signal }) => {
const runner = createRunner(__dirname)
Expand All @@ -14,7 +14,7 @@ it('Hono app captures errors', async ({ signal }) => {
values: [
{
type: 'Error',
value: 'Test error from Hono app',
value: 'Test error from Hono app (Sentry Cloudflare SDK)',
stacktrace: {
frames: expect.any(Array),
},
Expand Down
40 changes: 40 additions & 0 deletions dev-packages/cloudflare-integration-tests/suites/hono-sdk/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { sentry } from '@sentry/hono/cloudflare-workers';
import { Hono } from 'hono';

interface Env {
SENTRY_DSN: string;
}

const app = new Hono<{ Bindings: Env }>();

app.use(
'*',
sentry(app, {
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
debug: true,
// todo - what is going on with this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
integrations: integrations => integrations.filter(integration => integration.name !== 'Hono'),
}),
);

app.get('/', c => {
return c.text('Hello from Hono on Cloudflare!');
});

app.get('/json', c => {
return c.json({ message: 'Hello from Hono', framework: 'hono', platform: 'cloudflare' });
});

app.get('/error', () => {
throw new Error('Test error from Hono app');
});

app.get('/hello/:name', c => {
const name = c.req.param('name');
return c.text(`Hello, ${name}!`);
});

export default app;
109 changes: 109 additions & 0 deletions dev-packages/cloudflare-integration-tests/suites/hono-sdk/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { SDK_VERSION } from '@sentry/core';
import { expect, it } from 'vitest';
import { SHORT_UUID_MATCHER, UUID_MATCHER } from '../../expect';
import { createRunner } from '../../runner';

it('Hono app captures errors (Hono SDK)', async ({ signal }) => {
const runner = createRunner(__dirname)
.expect(envelope => {
const [, envelopeItems] = envelope;
const [itemHeader, itemPayload] = envelopeItems[0];

expect(itemHeader.type).toBe('event');

// todo: check with function eventEnvelope

// Validate error event structure
expect(itemPayload).toMatchObject({
level: 'error',
platform: 'javascript',
transaction: 'GET /error',
// fixme: should be hono
sdk: { name: 'sentry.javascript.cloudflare', version: SDK_VERSION },
// fixme: should contain trace
// trace: expect.objectContaining({ trace_id: UUID_MATCHER }),
exception: {
values: expect.arrayContaining([
expect.objectContaining({
type: 'Error',
value: 'Test error from Hono app',
mechanism: expect.objectContaining({
type: 'generic', // fixme: should be 'auto.faas.hono.error_handler'
handled: true, // fixme: should be false
}),
}),
]),
},
request: expect.objectContaining({
method: 'GET',
url: expect.stringContaining('/error'),
}),
});
})
.expect(envelope => {
const [, envelopeItems] = envelope;
const [itemHeader, itemPayload] = envelopeItems[0];

expect(itemHeader.type).toBe('transaction');

expect(itemPayload).toMatchObject({
type: 'transaction',
platform: 'javascript',
transaction: 'GET /error',
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
op: 'http.server',
status: 'internal_error',
origin: 'auto.http.cloudflare',
},
},
request: expect.objectContaining({
method: 'GET',
url: expect.stringContaining('/error'),
}),
});
})

.unordered()
.start(signal);

await runner.makeRequest('get', '/error', { expectError: true });
await runner.completed();
});

it('Hono app captures parametrized names', async ({ signal }) => {
const runner = createRunner(__dirname)
.expect(envelope => {
const [, envelopeItems] = envelope;
const [itemHeader, itemPayload] = envelopeItems[0];

expect(itemHeader.type).toBe('transaction');

expect(itemPayload).toMatchObject({
type: 'transaction',
platform: 'javascript',
transaction: 'GET /hello/:name',
contexts: {
trace: {
span_id: SHORT_UUID_MATCHER,
trace_id: UUID_MATCHER,
op: 'http.server',
status: 'ok',
origin: 'auto.http.cloudflare',
},
},
request: expect.objectContaining({
method: 'GET',
url: expect.stringContaining('/hello/:name'),
}),
});
})

.unordered()
.start(signal);

await runner.makeRequest('get', '/hello/:name', { expectError: false });
await runner.completed();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "hono-sdk-worker",
"compatibility_date": "2025-06-17",
"main": "index.ts",
"compatibility_flags": ["nodejs_compat"]
}

3 changes: 2 additions & 1 deletion dev-packages/cloudflare-integration-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// global fetch available in tests in lower Node versions.
"lib": ["ES2020"],
"esModuleInterop": true,
"types": ["@cloudflare/workers-types"]
"types": ["@cloudflare/workers-types"],
"moduleResolution": "bundler"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"packages/feedback",
"packages/gatsby",
"packages/google-cloud-serverless",
"packages/hono",
"packages/integration-shims",
"packages/nestjs",
"packages/nextjs",
Expand Down
9 changes: 9 additions & 0 deletions packages/hono/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
env: {
node: true,
},
extends: ['../../.eslintrc.js'],
rules: {
'@sentry-internal/sdk/no-class-field-initializers': 'off',
},
};
21 changes: 21 additions & 0 deletions packages/hono/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Functional Software, Inc. dba Sentry

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions packages/hono/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<p align="center">
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
</a>
</p>

# Official Sentry SDK for Hono (ALPHA)

[![npm version](https://img.shields.io/npm/v/@sentry/hono.svg)](https://www.npmjs.com/package/@sentry/hono)
[![npm dm](https://img.shields.io/npm/dm/@sentry/hono.svg)](https://www.npmjs.com/package/@sentry/hono)
[![npm dt](https://img.shields.io/npm/dt/@sentry/hono.svg)](https://www.npmjs.com/package/@sentry/hono)

## Links

- [Official SDK Docs](https://docs.sentry.io/quickstart/)

## Install

To get started, first install the `@sentry/hono` package:

```bash
npm install @sentry/hono
```

## Setup (Cloudflare Workers)

### Enable Node.js compatibility

Either set the `nodejs_als` or `nodejs_compat` compatibility flags in your `wrangler.jsonc`/`wrangler.toml` config. This is because the SDK needs access to the `AsyncLocalStorage` API to work correctly.

```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
{
"compatibility_flags": [
"nodejs_als",
// "nodejs_compat"
],
}
```

```toml {tabTitle:Toml} {filename:wrangler.toml}
compatibility_flags = ["nodejs_als"]
# compatibility_flags = ["nodejs_compat"]
```
100 changes: 100 additions & 0 deletions packages/hono/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"name": "@sentry/hono",
"version": "10.33.0",
"description": "Official Sentry SDK for Hono (ALPHA)",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/hono",
"author": "Sentry",
"license": "MIT",
"engines": {
"node": ">=18"
},
"files": [
"/build"
],
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"types": "build/types/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./build/types/index.d.ts",
"default": "./build/esm/index.js"
},
"require": {
"types": "./build/types/index.d.ts",
"default": "./build/cjs/index.js"
}
},
"./cloudflare-workers": {
"import": {
"types": "./build/types/index.cloudflare.d.ts",
"default": "./build/esm/index.cloudflare.js"
},
"require": {
"types": "./build/types/index.cloudflare.d.ts",
"default": "./build/cjs/index.cloudflare.js"
}
}
},
"typesVersions": {
"<5.0": {
"build/types/index.d.ts": [
"build/types-ts3.8/index.d.ts"
],
"build/types/index.cloudflare.d.ts": [
"build/types-ts3.8/index.cloudflare.d.ts"
]
}
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@sentry/cloudflare": "10.33.0",
"@sentry/core": "10.33.0",
"@sentry/node": "10.33.0"
},
"peerDependencies": {
"@cloudflare/workers-types": "^4.x",
"hono": "^4.10.4"
},
"peerDependenciesMeta": {
"@cloudflare/workers-types": {
"optional": true
}
},
"devDependencies": {
"@cloudflare/workers-types": "4.20250922.0",
"@types/node": "^18.19.1",
"wrangler": "4.22.0"
},
"scripts": {
"build": "run-p build:transpile build:types",
"build:dev": "yarn build",
"build:transpile": "rollup -c rollup.npm.config.mjs",
"build:types": "run-s build:types:core build:types:downlevel",
"build:types:core": "tsc -p tsconfig.types.json",
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
"build:watch": "run-p build:transpile:watch build:types:watch",
"build:dev:watch": "yarn build:watch",
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:tarball": "npm pack",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage sentry-hono-*.tgz",
"fix": "eslint . --format stylish --fix",
"lint": "eslint . --format stylish",
"lint:es-compatibility": "es-check es2022 ./build/cjs/*.js && es-check es2022 ./build/esm/*.js --module",
"test": "yarn test:unit",
"test:unit": "vitest run",
"test:watch": "vitest --watch",
"yalc:publish": "yalc publish --push --sig"
},
"volta": {
"extends": "../../package.json"
},
"sideEffects": false
}
Loading
Loading