(app: Hono<E>, options?: SentryHonoMiddlewareOptions)
| 16 | * **Note:** You must initialize Sentry separately before using this middleware. Typically, this is done by calling `Sentry.init()` in an `instrument.ts` file and loading it via the Node `--import` flag. |
| 17 | */ |
| 18 | export const sentry = <E extends Env>(app: Hono<E>, options?: SentryHonoMiddlewareOptions): MiddlewareHandler => { |
| 19 | const sentryClient = getClient(); |
| 20 | if (sentryClient === undefined) { |
| 21 | consoleSandbox(() => { |
| 22 | // eslint-disable-next-line no-console |
| 23 | console.warn( |
| 24 | '[@sentry/hono] Sentry is not initialized. Call `init()` from `@sentry/hono/node` in an `instrument.ts` file loaded via `--import` to set up Sentry for your application.', |
| 25 | ); |
| 26 | }); |
| 27 | } else { |
| 28 | const isInitializedWithHonoSdk = sentryClient.getOptions()._metadata?.sdk?.name === 'sentry.javascript.hono'; |
| 29 | |
| 30 | if (!isInitializedWithHonoSdk) { |
| 31 | consoleSandbox(() => { |
| 32 | // eslint-disable-next-line no-console |
| 33 | console.warn( |
| 34 | '[Sentry] Sentry was not initialized with `@sentry/hono/node`. Please import from `@sentry/hono/node` to ensure Hono-specific instrumentation is applied correctly.', |
| 35 | ); |
| 36 | }); |
| 37 | } else { |
| 38 | sentryClient.getOptions().debug && |
| 39 | debug.log('Sentry is initialized, proceeding to set up Hono `sentry` middleware.'); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | applyPatches(app); |
| 44 | |
| 45 | return async (context, next) => { |
| 46 | requestHandler(context, getConnInfo); |
| 47 | |
| 48 | await next(); // Handler runs in between Request above ⤴ and Response below ⤵ |
| 49 | |
| 50 | responseHandler(context, options?.shouldHandleError); |
| 51 | }; |
| 52 | }; |
no test coverage detected