Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
5.3 KiB
Plaintext
1 line
5.3 KiB
Plaintext
{"version":3,"file":"wrapPageComponentWithSentry.js","sources":["../../../../src/common/pages-router-instrumentation/wrapPageComponentWithSentry.ts"],"sourcesContent":["import { captureException, extractTraceparentData, getCurrentScope, withIsolationScope } from '@sentry/core';\n\ninterface FunctionComponent {\n (...args: unknown[]): unknown;\n}\n\ninterface ClassComponent {\n new (...args: unknown[]): {\n props?: unknown;\n render(...args: unknown[]): unknown;\n };\n}\n\nfunction isReactClassComponent(target: unknown): target is ClassComponent {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return typeof target === 'function' && target?.prototype?.isReactComponent;\n}\n\n/**\n * Wraps a page component with Sentry error instrumentation.\n */\nexport function wrapPageComponentWithSentry(pageComponent: FunctionComponent | ClassComponent): unknown {\n if (isReactClassComponent(pageComponent)) {\n return class SentryWrappedPageComponent extends pageComponent {\n public render(...args: unknown[]): unknown {\n return withIsolationScope(() => {\n const scope = getCurrentScope();\n // We extract the sentry trace data that is put in the component props by datafetcher wrappers\n const sentryTraceData =\n typeof this.props === 'object' &&\n this.props !== null &&\n '_sentryTraceData' in this.props &&\n typeof this.props._sentryTraceData === 'string'\n ? this.props._sentryTraceData\n : undefined;\n\n if (sentryTraceData) {\n const traceparentData = extractTraceparentData(sentryTraceData);\n scope.setContext('trace', {\n span_id: traceparentData?.parentSpanId,\n trace_id: traceparentData?.traceId,\n });\n }\n\n try {\n return super.render(...args);\n } catch (e) {\n captureException(e, {\n mechanism: {\n handled: false,\n type: 'auto.function.nextjs.page_class',\n },\n });\n throw e;\n }\n });\n }\n };\n } else if (typeof pageComponent === 'function') {\n return new Proxy(pageComponent, {\n apply(target, thisArg, argArray: [{ _sentryTraceData?: string } | undefined]) {\n return withIsolationScope(() => {\n const scope = getCurrentScope();\n // We extract the sentry trace data that is put in the component props by datafetcher wrappers\n const sentryTraceData = argArray?.[0]?._sentryTraceData;\n\n if (sentryTraceData) {\n const traceparentData = extractTraceparentData(sentryTraceData);\n scope.setContext('trace', {\n span_id: traceparentData?.parentSpanId,\n trace_id: traceparentData?.traceId,\n });\n }\n\n try {\n return target.apply(thisArg, argArray);\n } catch (e) {\n captureException(e, {\n mechanism: {\n handled: false,\n type: 'auto.function.nextjs.page_function',\n },\n });\n throw e;\n }\n });\n },\n });\n } else {\n return pageComponent;\n }\n}\n"],"names":["withIsolationScope","getCurrentScope","extractTraceparentData","captureException"],"mappings":";;;;AAaA,SAAS,qBAAqB,CAAC,MAAM,EAAqC;AAC1E;AACA,EAAE,OAAO,OAAO,MAAA,KAAW,UAAA,IAAc,MAAM,EAAE,SAAS,EAAE,gBAAgB;AAC5E;;AAEA;AACA;AACA;AACO,SAAS,2BAA2B,CAAC,aAAa,EAA+C;AACxG,EAAE,IAAI,qBAAqB,CAAC,aAAa,CAAC,EAAE;AAC5C,IAAI,OAAO,MAAM,0BAAA,SAAmC,aAAA,CAAc;AAClE,OAAa,MAAM,CAAC,GAAG,IAAI,EAAsB;AACjD,QAAQ,OAAOA,uBAAkB,CAAC,MAAM;AACxC,UAAU,MAAM,KAAA,GAAQC,oBAAe,EAAE;AACzC;AACA,UAAU,MAAM,eAAA;AAChB,YAAY,OAAO,IAAI,CAAC,KAAA,KAAU,QAAA;AAClC,YAAY,IAAI,CAAC,KAAA,KAAU,IAAA;AAC3B,YAAY,kBAAA,IAAsB,IAAI,CAAC,KAAA;AACvC,YAAY,OAAO,IAAI,CAAC,KAAK,CAAC,qBAAqB;AACnD,gBAAgB,IAAI,CAAC,KAAK,CAAC;AAC3B,gBAAgB,SAAS;;AAEzB,UAAU,IAAI,eAA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