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
11 KiB
Plaintext
1 line
11 KiB
Plaintext
{"version":3,"file":"third-party-errors-filter.js","sources":["../../../src/integrations/third-party-errors-filter.ts"],"sourcesContent":["import { defineIntegration } from '../integration';\nimport { addMetadataToStackFrames, stripMetadataFromStackFrames } from '../metadata';\nimport type { EventItem } from '../types-hoist/envelope';\nimport type { Event } from '../types-hoist/event';\nimport type { StackFrame } from '../types-hoist/stackframe';\nimport { forEachEnvelopeItem } from '../utils/envelope';\nimport { getFramesFromEvent } from '../utils/stacktrace';\n\ninterface Options {\n /**\n * Keys that have been provided in the Sentry bundler plugin via the the `applicationKey` option, identifying your bundles.\n *\n * - Webpack plugin: https://www.npmjs.com/package/@sentry/webpack-plugin#applicationkey\n * - Vite plugin: https://www.npmjs.com/package/@sentry/vite-plugin#applicationkey\n * - Esbuild plugin: https://www.npmjs.com/package/@sentry/esbuild-plugin#applicationkey\n * - Rollup plugin: https://www.npmjs.com/package/@sentry/rollup-plugin#applicationkey\n */\n filterKeys: string[];\n\n /**\n * Defines how the integration should behave. \"Third-Party Stack Frames\" are stack frames that did not come from files marked with a matching bundle key.\n *\n * You can define the behaviour with one of 4 modes:\n * - `drop-error-if-contains-third-party-frames`: Drop error events that contain at least one third-party stack frame.\n * - `drop-error-if-exclusively-contains-third-party-frames`: Drop error events that exclusively contain third-party stack frames.\n * - `apply-tag-if-contains-third-party-frames`: Keep all error events, but apply a `third_party_code: true` tag in case the error contains at least one third-party stack frame.\n * - `apply-tag-if-exclusively-contains-third-party-frames`: Keep all error events, but apply a `third_party_code: true` tag in case the error contains exclusively third-party stack frames.\n *\n * If you chose the mode to only apply tags, the tags can then be used in Sentry to filter your issue stream by entering `!third_party_code:True` in the search bar.\n */\n behaviour:\n | 'drop-error-if-contains-third-party-frames'\n | 'drop-error-if-exclusively-contains-third-party-frames'\n | 'apply-tag-if-contains-third-party-frames'\n | 'apply-tag-if-exclusively-contains-third-party-frames';\n\n /**\n * @experimental\n * If set to true, the integration will ignore frames that are internal to the Sentry SDK from the third-party frame detection.\n * Note that enabling this option might lead to errors being misclassified as third-party errors.\n */\n ignoreSentryInternalFrames?: boolean;\n}\n\n/**\n * This integration allows you to filter out, or tag error events that do not come from user code marked with a bundle key via the Sentry bundler plugins.\n */\nexport const thirdPartyErrorFilterIntegration = defineIntegration((options: Options) => {\n return {\n name: 'ThirdPartyErrorsFilter',\n setup(client) {\n // We need to strip metadata from stack frames before sending them to Sentry since these are client side only.\n client.on('beforeEnvelope', envelope => {\n forEachEnvelopeItem(envelope, (item, type) => {\n if (type === 'event') {\n const event = Array.isArray(item) ? (item as EventItem)[1] : undefined;\n\n if (event) {\n stripMetadataFromStackFrames(event);\n item[1] = event;\n }\n }\n });\n });\n\n client.on('applyFrameMetadata', event => {\n // Only apply stack frame metadata to error events\n if (event.type) {\n return;\n }\n\n const stackParser = client.getOptions().stackParser;\n addMetadataToStackFrames(stackParser, event);\n });\n },\n\n processEvent(event) {\n const frameKeys = getBundleKeysForAllFramesWithFilenames(event, options.ignoreSentryInternalFrames);\n\n if (frameKeys) {\n const arrayMethod =\n options.behaviour === 'drop-error-if-contains-third-party-frames' ||\n options.behaviour === 'apply-tag-if-contains-third-party-frames'\n ? 'some'\n : 'every';\n\n const behaviourApplies = frameKeys[arrayMethod](keys => !keys.some(key => options.filterKeys.includes(key)));\n\n if (behaviourApplies) {\n const shouldDrop =\n options.behaviour === 'drop-error-if-contains-third-party-frames' ||\n options.behaviour === 'drop-error-if-exclusively-contains-third-party-frames';\n if (shouldDrop) {\n return null;\n } else {\n event.tags = {\n ...event.tags,\n third_party_code: true,\n };\n }\n }\n }\n\n return event;\n },\n };\n});\n\n/**\n * Checks if a stack frame is a Sentry internal frame by strictly matching:\n * 1. The frame must be the last frame in the stack\n * 2. The filename must indicate the internal helpers file\n * 3. The context_line must contain the exact pattern \"fn.apply(this, wrappedArguments)\"\n * 4. The comment pattern \"Attempt to invoke user-land function\" must be present in pre_context\n *\n */\nfunction isSentryInternalFrame(frame: StackFrame, frameIndex: number): boolean {\n // Only match the last frame (index 0 in reversed stack)\n if (frameIndex !== 0 || !frame.context_line || !frame.filename) {\n return false;\n }\n\n if (\n !frame.filename.includes('sentry') ||\n !frame.filename.includes('helpers') || // Filename would look something like this: 'node_modules/@sentry/browser/build/npm/esm/helpers.js'\n !frame.context_line.includes(SENTRY_INTERNAL_FN_APPLY) // Must have context_line with the exact fn.apply pattern\n ) {\n return false;\n }\n\n // Check pre_context array for comment pattern\n if (frame.pre_context) {\n const len = frame.pre_context.length;\n for (let i = 0; i < len; i++) {\n if (frame.pre_context[i]?.includes(SENTRY_INTERNAL_COMMENT)) {\n return true;\n }\n }\n }\n\n return false;\n}\n\nfunction getBundleKeysForAllFramesWithFilenames(\n event: Event,\n ignoreSentryInternalFrames?: boolean,\n): string[][] | undefined {\n const frames = getFramesFromEvent(event);\n\n if (!frames) {\n return undefined;\n }\n\n return frames\n .filter((frame, index) => {\n // Exclude frames without a filename\n if (!frame.filename) {\n return false;\n }\n // Exclude frames without location info, since these are likely native code or built-ins.\n // JS frames have lineno/colno, WASM frames have instruction_addr instead.\n if (frame.lineno == null && frame.colno == null && frame.instruction_addr == null) {\n return false;\n }\n // Optionally ignore Sentry internal frames\n return !ignoreSentryInternalFrames || !isSentryInternalFrame(frame, index);\n })\n .map(frame => {\n if (!frame.module_metadata) {\n return [];\n }\n return Object.keys(frame.module_metadata)\n .filter(key => key.startsWith(BUNDLER_PLUGIN_APP_KEY_PREFIX))\n .map(key => key.slice(BUNDLER_PLUGIN_APP_KEY_PREFIX.length));\n });\n}\n\nconst BUNDLER_PLUGIN_APP_KEY_PREFIX = '_sentryBundlerPluginAppKey:';\nconst SENTRY_INTERNAL_COMMENT = 'Attempt to invoke user-land function';\nconst SENTRY_INTERNAL_FN_APPLY = 'fn.apply(this, wrappedArguments)';\n"],"names":["defineIntegration","envelope","forEachEnvelopeItem","stripMetadataFromStackFrames","addMetadataToStackFrames","getFramesFromEvent"],"mappings":";;;;;;;AA4CA;AACA;AACA;AACO,MAAM,mCAAmCA,6BAAiB,CAAC,CAAC,OAAO,KAAc;AACxF,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,wBAAwB;AAClC,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB;AACA,MAAM,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAEC,cAAY;AAC9C,QAAQC,4BAAmB,CAACD,UAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK;AACtD,UAAU,IAAI,IAAA,KAAS,OAAO,EAAE;AAChC,YAAY,MAAM,KAAA,GAAQ,KAAK,CAAC,OAAO,CAAC,IAAI,CAAA,GAAI,CAAC,IAAA,GAAmB,CAAC,CAAA,GAAI,SAAS;;AAElF,YAAY,IAAI,KAAK,EAAE;AACvB,cAAcE,qCAA4B,CAAC,KAAK,CAAC;AACjD,cAAc,IAAI,CAAC,CAAC,CAAA,GAAI,KAAK;AAC7B,YAAY;AACZ,UAAU;AACV,QAAQ,CAAC,CAAC;AACV,MAAM,CAAC,CAAC;;AAER,MAAM,MAAM,CAAC,EAAE,CAAC,oBAAoB,EAAE,SAAS;AAC/C;AACA,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE;AACxB,UAAU;AACV,QAAQ;;AAER,QAAQ,MAAM,cAAc,MAAM,CAAC,UAAU,EAAE,CAAC,WAAW;AAC3D,QAAQC,iCAAwB,CAAC,WAAW,EAAE,KAAK,CAAC;AACpD,MAAM,CAAC,CAAC;AACR,IAAI,CAAC;;AAEL,IAAI,YAAY,CAAC,KAAK,EAAE;AACxB,MAAM,MAAM,SAAA,GAAY,sCAAsC,CAAC,KAAK,E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