@@ -28,6 +28,48 @@ Select which Sentry features you'd like to install in addition to Error Monitori
2828
2929Since Hono is a framework designed to run in all kinds of JavaScript runtimes, different setups for different platforms are outlined below.
3030
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+
3173### Setup On Cloudflare Workers
3274
3375``` bash {tabTitle:npm}
@@ -62,24 +104,50 @@ compatibility_flags = ["nodejs_als"]
62104Next, wrap your handler with the ` withSentry ` function. This will initialize the SDK and hook into the
63105environment. Note that you can turn off almost all side effects using the respective options.
64106
65-
66-
67107``` typescript {filename:index.ts}
68- import { Hono } from " hono" ;
108+ import { Hono , HTTPException } from " hono" ;
69109import * as Sentry from " @sentry/cloudflare" ;
70110
71- const app = new Hono ();
111+ Sentry .init ({
112+ dsn: " ___PUBLIC_DSN___" ,
113+
72114
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
76125});
77126
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.
78146export default Sentry .withSentry (
79147 (env ) => ({
80148 dsn: " ___PUBLIC_DSN___" ,
81149
82-
150+
83151 // Adds request headers and IP for users, for more info visit:
84152 // https://docs.sentry.io/platforms/javascript/guides/hono/configuration/options/#sendDefaultPii
85153 sendDefaultPii: true ,
0 commit comments