@@ -28,6 +28,48 @@ Select which Sentry features you'd like to install in addition to Error Monitori
28
28
29
29
Since Hono is a framework designed to run in all kinds of JavaScript runtimes, different setups for different platforms are outlined below.
30
30
31
+ ### Setup On Node.js
32
+
33
+ ``` bash {tabTitle:npm}
34
+ npm install @sentry/node --save
35
+ ```
36
+
37
+ ``` bash {tabTitle:yarn}
38
+ yarn add @sentry/node
39
+ ```
40
+
41
+ ``` bash {tabTitle:pnpm}
42
+ pnpm add @sentry/node
43
+ ```
44
+
45
+ From there, you'll need to bind an ` onError ` hook to report unhandled exceptions to Sentry:
46
+
47
+ ``` typescript {filename:index.ts}
48
+ import { Hono , HTTPException } from " hono" ;
49
+ import * as Sentry from " @sentry/node" ;
50
+
51
+ const app = new Hono ()
52
+ // Add an onError hook to report unhandled exceptions to Sentry.
53
+ .onError ((err , c ) => {
54
+ // Report _all_ unhandled errors.
55
+ Sentry .captureException (err );
56
+ if (err instanceof HTTPException ) {
57
+ return err .getResponse ()
58
+ }
59
+ // Or just report errors which are not instances of HTTPException
60
+ // Sentry.captureException(err);
61
+ return c .json ({ error: " Internal server error" }, 500 )
62
+ })
63
+ // Your routes...
64
+ app .get (" /" , () => {
65
+ // ...
66
+ });
67
+
68
+ export default app ;
69
+ ```
70
+
71
+ Note: We don't currently support automatic tracing instrumentation for Hono within the Node.js adapter.
72
+
31
73
### Setup On Cloudflare Workers
32
74
33
75
``` bash {tabTitle:npm}
@@ -62,24 +104,50 @@ compatibility_flags = ["nodejs_als"]
62
104
Next, wrap your handler with the ` withSentry ` function. This will initialize the SDK and hook into the
63
105
environment. Note that you can turn off almost all side effects using the respective options.
64
106
65
-
66
-
67
107
``` typescript {filename:index.ts}
68
- import { Hono } from " hono" ;
108
+ import { Hono , HTTPException } from " hono" ;
69
109
import * as Sentry from " @sentry/cloudflare" ;
70
110
71
- const app = new Hono ();
111
+ Sentry .init ({
112
+ dsn: " ___PUBLIC_DSN___" ,
113
+
72
114
73
- // Your routes...
74
- app .get (" /" , () => {
75
- // ...
115
+ // Adds request headers and IP for users, for more info visit:
116
+ // https://docs.sentry.io/platforms/javascript/guides/hono/configuration/options/#sendDefaultPii
117
+ sendDefaultPii: true ,
118
+
119
+ // ___PRODUCT_OPTION_START___ performance
120
+ // Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
121
+ // Learn more at
122
+ // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
123
+ tracesSampleRate: 1.0 ,
124
+ // ___PRODUCT_OPTION_END___ performance
76
125
});
77
126
127
+ const app = new Hono ()
128
+ // Add an onError hook to report unhandled exceptions to Sentry.
129
+ .onError ((err , c ) => {
130
+ // Report _all_ unhandled errors.
131
+ Sentry .captureException (err );
132
+ if (err instanceof HTTPException ) {
133
+ return err .getResponse ()
134
+ }
135
+ // Or just report errors which are not instances of HTTPException
136
+ // Sentry.captureException(err);
137
+ return c .json ({ error: " Internal server error" }, 500 )
138
+ })
139
+ // Your routes...
140
+ app .get (" /" , () => {
141
+ // ...
142
+ });
143
+
144
+ // Wrap your Worker binding with Sentry to ensure tracing instrumentation is enabled,
145
+ // and Sentry telemetry is flushed at the end of requests.
78
146
export default Sentry .withSentry (
79
147
(env ) => ({
80
148
dsn: " ___PUBLIC_DSN___" ,
81
149
82
-
150
+
83
151
// Adds request headers and IP for users, for more info visit:
84
152
// https://docs.sentry.io/platforms/javascript/guides/hono/configuration/options/#sendDefaultPii
85
153
sendDefaultPii: true ,
0 commit comments