Skip to content

Commit d76c5bd

Browse files
committed
feat(hono): Add runtime packages as optional peer dependencies
1 parent 29604aa commit d76c5bd

3 files changed

Lines changed: 78 additions & 8 deletions

File tree

dev-packages/e2e-tests/test-applications/hono-4/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"test:assert": "TEST_ENV=production playwright test"
1313
},
1414
"dependencies": {
15+
"@sentry/bun": "latest || *",
16+
"@sentry/cloudflare": "latest || *",
1517
"@sentry/hono": "latest || *",
1618
"@sentry/node": "latest || *",
1719
"@hono/node-server": "^1.19.10",

packages/hono/README.md

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ npm install @sentry/hono
2929

3030
## Setup (Cloudflare Workers)
3131

32-
### 1. Enable Node.js compatibility
32+
### 1. Install Peer Dependency
33+
34+
Additionally to `@sentry/hono`, install the `@sentry/cloudflare` package:
35+
36+
```bashbash
37+
npm install --save @sentry/cloudflare
38+
```
39+
40+
Make sure the installed version always stays in sync. The `@sentry/cloudflare` package is a required peer dependency when using `@sentry/hono/cloudflare`.
41+
You won't import `@sentry/cloudflare` directly in your code, but it needs to be installed in your project.
42+
43+
### 2. Enable Node.js compatibility
3344

3445
Set the `nodejs_compat` compatibility flag in your `wrangler.jsonc`/`wrangler.toml` config. This is because the SDK needs access to the `AsyncLocalStorage` API to work correctly.
3546

@@ -43,7 +54,7 @@ Set the `nodejs_compat` compatibility flag in your `wrangler.jsonc`/`wrangler.to
4354
compatibility_flags = ["nodejs_compat"]
4455
```
4556

46-
### 2. Initialize Sentry in your Hono app
57+
### 3. Initialize Sentry in your Hono app
4758

4859
Initialize the Sentry Hono middleware as early as possible in your app:
4960

@@ -85,7 +96,18 @@ export default app;
8596

8697
## Setup (Node)
8798

88-
### 1. Initialize Sentry in your Hono app
99+
### 1. Install Peer Dependency
100+
101+
Additionally to `@sentry/hono`, install the `@sentry/node` package:
102+
103+
```bashbash
104+
npm install --save @sentry/node
105+
```
106+
107+
Make sure the installed version always stays in sync. The `@sentry/node` package is a required peer dependency when using `@sentry/hono/node`.
108+
You won't import `@sentry/node` directly in your code, but it needs to be installed in your project.
109+
110+
### 2. Initialize Sentry in your Hono app
89111

90112
Initialize the Sentry Hono middleware as early as possible in your app:
91113

@@ -109,7 +131,7 @@ app.use(
109131
serve(app);
110132
```
111133

112-
### 2. Add `preload` script to start command
134+
### 3. Add `preload` script to start command
113135

114136
To ensure that Sentry can capture spans from third-party libraries (e.g. database clients) used in your Hono app, Sentry needs to wrap these libraries as early as possible.
115137

@@ -126,3 +148,40 @@ NODE_OPTIONS="--import @sentry/node/preload"
126148
```
127149

128150
Read more about this preload script in the docs: https://docs.sentry.io/platforms/javascript/guides/hono/install/late-initialization/#late-initialization-with-esm
151+
152+
## Setup (Bun)
153+
154+
### 1. Install Peer Dependency
155+
156+
Additionally to `@sentry/hono`, install the `@sentry/bun` package:
157+
158+
```bashbash
159+
npm install --save @sentry/bun
160+
```
161+
162+
Make sure the installed version always stays in sync. The `@sentry/bun` package is a required peer dependency when using `@sentry/hono/bun`.
163+
You won't import `@sentry/bun` directly in your code, but it needs to be installed in your project.
164+
165+
### 2. Initialize Sentry in your Hono app
166+
167+
Initialize the Sentry Hono middleware as early as possible in your app:
168+
169+
```ts
170+
import { Hono } from 'hono';
171+
import { serve } from '@hono/node-server';
172+
import { sentry } from '@sentry/hono/bun';
173+
174+
const app = new Hono();
175+
176+
// Initialize Sentry middleware right after creating the app
177+
app.use(
178+
sentry(app, {
179+
dsn: '__DSN__', // or process.env.SENTRY_DSN or Bun.env.SENTRY_DSN
180+
tracesSampleRate: 1.0,
181+
}),
182+
);
183+
184+
// ... your routes and other middleware
185+
186+
serve(app);
187+
```

packages/hono/package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,27 @@
7979
},
8080
"dependencies": {
8181
"@opentelemetry/api": "^1.9.1",
82-
"@sentry/bun": "10.49.0",
83-
"@sentry/cloudflare": "10.49.0",
84-
"@sentry/core": "10.49.0",
85-
"@sentry/node": "10.49.0"
82+
"@sentry/core": "10.49.0"
8683
},
8784
"peerDependencies": {
8885
"@cloudflare/workers-types": "^4.x",
86+
"@sentry/bun": "10.49.0",
87+
"@sentry/cloudflare": "10.49.0",
88+
"@sentry/node": "10.49.0",
8989
"hono": "^4.x"
9090
},
9191
"peerDependenciesMeta": {
9292
"@cloudflare/workers-types": {
9393
"optional": true
94+
},
95+
"@sentry/bun": {
96+
"optional": true
97+
},
98+
"@sentry/cloudflare": {
99+
"optional": true
100+
},
101+
"@sentry/node": {
102+
"optional": true
94103
}
95104
},
96105
"devDependencies": {

0 commit comments

Comments
 (0)