MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / sentry

Function sentry

packages/hono/src/cloudflare/middleware.ts:16–54  ·  view source on GitHub ↗
(
  app: Hono<E>,
  options: HonoCloudflareOptions | ((env: E['Bindings']) => HonoCloudflareOptions),
)

Source from the content-addressed store, hash-verified

14 * Sentry middleware for Hono on Cloudflare Workers.
15 */
16export 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}

Callers 2

index.tsFile · 0.90

Calls 9

withSentryFunction · 0.90
applySdkMetadataFunction · 0.90
applyPatchesFunction · 0.90
requestHandlerFunction · 0.90
responseHandlerFunction · 0.90
optionsFunction · 0.85
nextFunction · 0.85
logMethod · 0.65

Tested by

no test coverage detected