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

Function sentry

packages/hono/src/node/middleware.ts:18–52  ·  view source on GitHub ↗
(app: Hono<E>, options?: SentryHonoMiddlewareOptions)

Source from the content-addressed store, hash-verified

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 */
18export 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};

Callers 2

entry.node.tsFile · 0.90
scenario.mjsFile · 0.90

Calls 9

getClientFunction · 0.90
consoleSandboxFunction · 0.90
applyPatchesFunction · 0.90
requestHandlerFunction · 0.90
responseHandlerFunction · 0.90
nextFunction · 0.85
warnMethod · 0.65
getOptionsMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected