( app: Hono<E>, options: HonoCloudflareOptions | ((env: E['Bindings']) => HonoCloudflareOptions), )
| 14 | * Sentry middleware for Hono on Cloudflare Workers. |
| 15 | */ |
| 16 | export function sentry<E extends Env>( |
| 17 | app: Hono<E>, |
| 18 | options: HonoCloudflareOptions | ((env: E['Bindings']) => HonoCloudflareOptions), |
| 19 | ): MiddlewareHandler { |
| 20 | withSentry( |
| 21 | env => { |
| 22 | const honoOptions = typeof options === 'function' ? options(env as E['Bindings']) : options; |
| 23 | |
| 24 | applySdkMetadata(honoOptions, 'hono', ['hono', 'cloudflare']); |
| 25 | |
| 26 | honoOptions.debug && debug.log('Initialized Sentry Hono middleware (Cloudflare)'); |
| 27 | |
| 28 | return { |
| 29 | ...honoOptions, |
| 30 | ignoreSpans: [...(honoOptions.ignoreSpans || []), ...LOW_QUALITY_TRANSACTION_PATTERNS], |
| 31 | // Always filter out the Hono integration from defaults and user integrations. |
| 32 | // The Hono integration is already set up by withSentry, so adding it again would cause capturing too early (in Cloudflare SDK) and non-parametrized URLs. |
| 33 | integrations: buildFilteredIntegrations(honoOptions.integrations, true), |
| 34 | }; |
| 35 | }, |
| 36 | // Cast needed because Hono<E> exposes a narrower fetch signature than ExportedHandler<unknown> |
| 37 | app as unknown as ExportedHandler<unknown>, |
| 38 | ); |
| 39 | |
| 40 | applyPatches(app); |
| 41 | |
| 42 | return async (context, next) => { |
| 43 | const shouldHandleError = |
| 44 | typeof options === 'function' |
| 45 | ? options(context.env as E['Bindings']).shouldHandleError |
| 46 | : options.shouldHandleError; |
| 47 | |
| 48 | requestHandler(context, getConnInfo); |
| 49 | |
| 50 | await next(); // Handler runs in between Request above ⤴ and Response below ⤵ |
| 51 | |
| 52 | responseHandler(context, shouldHandleError); |
| 53 | }; |
| 54 | } |
no test coverage detected