package.build.cjs.metadata.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Base implementation for all Sentry JavaScript SDKs
{"version":3,"file":"metadata.js","sources":["../../src/metadata.ts"],"sourcesContent":["import type { Event, StackParser } from '@sentry/types';\nimport { GLOBAL_OBJ } from '@sentry/utils';\n\n/** Keys are source filename/url, values are metadata objects. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst filenameMetadataMap = new Map();\n/** Set of stack strings that have already been parsed. */\nconst parsedStacks = new Set();\n\nfunction ensureMetadataStacksAreParsed(parser: StackParser): void {\n if (!GLOBAL_OBJ._sentryModuleMetadata) {\n return;\n }\n\n for (const stack of Object.keys(GLOBAL_OBJ._sentryModuleMetadata)) {\n const metadata = GLOBAL_OBJ._sentryModuleMetadata[stack];\n\n if (parsedStacks.has(stack)) {\n continue;\n }\n\n // Ensure this stack doesn't get parsed again\n parsedStacks.add(stack);\n\n const frames = parser(stack);\n\n // Go through the frames starting from the top of the stack and find the first one with a filename\n for (const frame of frames.reverse()) {\n if (frame.filename) {\n // Save the metadata for this filename\n filenameMetadataMap.set(frame.filename, metadata);\n break;\n }\n }\n }\n}\n\n/**\n * Retrieve metadata for a specific JavaScript file URL.\n *\n * Metadata is injected by the Sentry bundler plugins using the `_experiments.moduleMetadata` config option.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getMetadataForUrl(parser: StackParser, filename: string): any | undefined {\n ensureMetadataStacksAreParsed(parser);\n return filenameMetadataMap.get(filename);\n}\n\n/**\n * Adds metadata to stack frames.\n *\n * Metadata is injected by the Sentry bundler plugins using the `_experiments.moduleMetadata` config option.\n */\nexport function addMetadataToStackFrames(parser: StackParser, event: Event): void {\n try {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n event.exception!.values!.forEach(exception => {\n if (!exception.stacktrace) {\n return;\n }\n\n for (const frame of exception.stacktrace.frames || []) {\n if (!frame.filename || frame.module_metadata) {\n continue;\n }\n\n const metadata = getMetadataForUrl(parser, frame.filename);\n\n if (metadata) {\n frame.module_metadata = metadata;\n }\n }\n });\n } catch (_) {\n // To save bundle size we're just try catching here instead of checking for the existence of all the different objects.\n }\n}\n\n/**\n * Strips metadata from stack frames.\n */\nexport function stripMetadataFromStackFrames(event: Event): void {\n try {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n event.exception!.values!.forEach(exception => {\n if (!exception.stacktrace) {\n return;\n }\n\n for (const frame of exception.stacktrace.frames || []) {\n delete frame.module_metadata;\n }\n });\n } catch (_) {\n // To save bundle size we're just try catching here instead of checking for the existence of all the different objects.\n }\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AAGA;AACA;AACA,MAAM,mBAAoB,GAAE,IAAI,GAAG,EAAe,CAAA;AAClD;AACA,MAAM,YAAa,GAAE,IAAI,GAAG,EAAU,CAAA;AACtC;AACA,SAAS,6BAA6B,CAAC,MAAM,EAAqB;AAClE,EAAE,IAAI,CAACA,gBAAU,CAAC,qBAAqB,EAAE;AACzC,IAAI,OAAM;AACV,GAAE;AACF;AACA,EAAE,KAAK,MAAM,KAAA,IAAS,MAAM,CAAC,IAAI,CAACA,gBAAU,CAAC,qBAAqB,CAAC,EAAE;AACrE,IAAI,MAAM,WAAWA,gBAAU,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAA;AAC5D;AACA,IAAI,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;AACjC,MAAM,SAAQ;AACd,KAAI;AACJ;AACA;AACA,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AAC3B;AACA,IAAI,MAAM,MAAO,GAAE,MAAM,CAAC,KAAK,CAAC,CAAA;AAChC;AACA;AACA,IAAI,KAAK,MAAM,KAAM,IAAG,MAAM,CAAC,OAAO,EAAE,EAAE;AAC1C,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE;AAC1B;AACA,QAAQ,mBAAmB,CAAC,GA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