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
{"version":3,"file":"captureconsole.js","sources":["../../../src/integrations/captureconsole.ts"],"sourcesContent":["import type { CaptureContext, IntegrationFn } from '@sentry/types';\nimport {\n CONSOLE_LEVELS,\n GLOBAL_OBJ,\n addConsoleInstrumentationHandler,\n addExceptionMechanism,\n safeJoin,\n severityLevelFromString,\n} from '@sentry/utils';\nimport { getClient, withScope } from '../currentScopes';\nimport { captureException, captureMessage } from '../exports';\nimport { defineIntegration } from '../integration';\n\ninterface CaptureConsoleOptions {\n levels?: string[];\n}\n\nconst INTEGRATION_NAME = 'CaptureConsole';\n\nconst _captureConsoleIntegration = ((options: CaptureConsoleOptions = {}) => {\n const levels = options.levels || CONSOLE_LEVELS;\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);\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): 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: false,\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":";;;;;;;AAiBA,MAAM,gBAAA,GAAmB,gBAAgB,CAAA;AACzC;AACA,MAAM,0BAAA,IAA8B,CAAC,OAAO,GAA0B,EAAE,KAAK;AAC7E,EAAE,MAAM,MAAO,GAAE,OAAO,CAAC,MAAA,IAAUA,oBAAc,CAAA;AACjD;AACA,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,IAAI,EAAE,aAAaC,gBAAU,CAAC,EAAE;AACtC,QAAQ,OAAM;AACd,OAAM;AACN;AACA,MAAMC,sCAAgC,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,OAAM;AAChB,SAAQ;AACR;AACA,QAAQ,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AACnC,OAAO,CAAC,CAAA;AACR,KAAK;AACL,GAAG,CAAA;AACH,CAAC,CAAE,EAAA;AACH;AACA;AACA;AACA;MACa,yBAA0B,GAAEC,6BAAiB,CAAC,0BAA0B,EAAC;AACtF;AACA,SAAS,cAAc,CAAC,IAAI,EAAa,KAAK,EAAgB;AAC9D,EAAE,MAAM,cAAc,GAAmB;AACzC,IAAI,KAAK,EAAEC,6BAAuB,CAAC,KAAK,CAAC;AACzC,IAAI,KAAK,EAAE;AACX,MAAM,SAAS,EAAE,IAAI;AACrB,KAAK;AACL,GAAG,CAAA;AACH;AACA,EAAEC,uBAAS,CAAC,KAAA,IAAS;AACrB,IAAI,KAAK,CAAC,iBAAiB,CAAC,SAAS;AACrC,MAAM,KAA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