package.build.cjs.integrations.captureconsole.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
The newest version!
{"version":3,"file":"captureconsole.js","sources":["../../../src/integrations/captureconsole.ts"],"sourcesContent":["import { getClient, withScope } from '../currentScopes';\nimport { captureException, captureMessage } from '../exports';\nimport { defineIntegration } from '../integration';\nimport type { CaptureContext, IntegrationFn } from '../types-hoist';\nimport { addConsoleInstrumentationHandler } from '../utils-hoist/instrument/console';\nimport { CONSOLE_LEVELS } from '../utils-hoist/logger';\nimport { addExceptionMechanism } from '../utils-hoist/misc';\nimport { severityLevelFromString } from '../utils-hoist/severity';\nimport { safeJoin } from '../utils-hoist/string';\nimport { GLOBAL_OBJ } from '../utils-hoist/worldwide';\n\ninterface CaptureConsoleOptions {\n levels?: string[];\n\n // TODO(v9): Flip default value to `true` and adjust JSDoc!\n /**\n * By default, Sentry will mark captured console messages as unhandled.\n * Set this to `true` if you want to mark them as handled instead.\n *\n * Note: in v9 of the SDK, this option will default to `true`, meaning the default behavior will change to mark console messages as handled.\n * @default false\n */\n handled?: boolean;\n}\n\nconst INTEGRATION_NAME = 'CaptureConsole';\n\nconst _captureConsoleIntegration = ((options: CaptureConsoleOptions = {}) => {\n const levels = options.levels || CONSOLE_LEVELS;\n // TODO(v9): Flip default value to `true`\n const handled = !!options.handled;\n\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n if (!('console' in GLOBAL_OBJ)) {\n return;\n }\n\n addConsoleInstrumentationHandler(({ args, level }) => {\n if (getClient() !== client || !levels.includes(level)) {\n return;\n }\n\n consoleHandler(args, level, handled);\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Send Console API calls as Sentry Events.\n */\nexport const captureConsoleIntegration = defineIntegration(_captureConsoleIntegration);\n\nfunction consoleHandler(args: unknown[], level: string, handled: boolean): void {\n const captureContext: CaptureContext = {\n level: severityLevelFromString(level),\n extra: {\n arguments: args,\n },\n };\n\n withScope(scope => {\n scope.addEventProcessor(event => {\n event.logger = 'console';\n\n addExceptionMechanism(event, {\n handled,\n type: 'console',\n });\n\n return event;\n });\n\n if (level === 'assert') {\n if (!args[0]) {\n const message = `Assertion failed: ${safeJoin(args.slice(1), ' ') || 'console.assert'}`;\n scope.setExtra('arguments', args.slice(1));\n captureMessage(message, captureContext);\n }\n return;\n }\n\n const error = args.find(arg => arg instanceof Error);\n if (error) {\n captureException(error, captureContext);\n return;\n }\n\n const message = safeJoin(args, ' ');\n captureMessage(message, captureContext);\n });\n}\n"],"names":["CONSOLE_LEVELS","GLOBAL_OBJ","addConsoleInstrumentationHandler","getClient","defineIntegration","severityLevelFromString","withScope","addExceptionMechanism","safeJoin","captureMessage","captureException"],"mappings":";;;;;;;;;;;;AAyBA,MAAM,gBAAA,GAAmB,gBAAgB;;AAEzC,MAAM,0BAAA,IAA8B,CAAC,OAAO,GAA0B,EAAE,KAAK;AAC7E,EAAE,MAAM,MAAO,GAAE,OAAO,CAAC,MAAA,IAAUA,qBAAc;AACjD;AACA,EAAE,MAAM,OAAQ,GAAE,CAAC,CAAC,OAAO,CAAC,OAAO;;AAEnC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,IAAI,EAAE,aAAaC,oBAAU,CAAC,EAAE;AACtC,QAAQ;AACR;;AAEA,MAAMC,wCAAgC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAA,EAAO,KAAK;AAC5D,QAAQ,IAAIC,uBAAS,OAAO,MAAA,IAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;AAC/D,UAAU;AACV;;AAEA,QAAQ,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC;AAC5C,OAAO,CAAC;AACR,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;AACA;AACA;MACa,yBAA0B,GAAEC,6BAAiB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