Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function consoleBreadcrumb(handlerData: { [key: string]: any }): void {
const breadcrumb = {
category: 'console',
data: {
extra: {
arguments: normalize(handlerData.args, 3),
},
logger: 'console',
},
level: Severity.fromString(handlerData.level),
message: safeJoin(handlerData.args, ' '),
};
if (handlerData.level === 'assert') {
if (handlerData.args[0] === false) {
breadcrumb.message = `Assertion failed: ${safeJoin(handlerData.args.slice(1), ' ') || 'console.assert'}`;
breadcrumb.data.extra.arguments = normalize(handlerData.args.slice(1), 3);
} else {
// Don't capture a breadcrumb for passed assertions
return;
}
}
getCurrentHub().addBreadcrumb(breadcrumb, {
input: handlerData.args,
level: handlerData.level,
function addSentryBreadcrumb(serializedData: string): void {
// There's always something that can go wrong with deserialization...
try {
const event = JSON.parse(serializedData);
getCurrentHub().addBreadcrumb(
{
category: 'sentry',
event_id: event.event_id,
level: event.level || Severity.fromString('error'),
message: getEventDescription(event),
},
{
event,
},
);
} catch (_oO) {
logger.error('Error while adding sentry type breadcrumb');
}
}
hub.withScope(scope => {
scope.setLevel(Severity.fromString(level));
scope.setExtra('arguments', normalize(args, 3));
scope.addEventProcessor(event => {
event.logger = 'console';
return event;
});
let message = safeJoin(args, ' ');
if (level === 'assert') {
if (args[0] === false) {
message = `Assertion failed: ${safeJoin(args.slice(1), ' ') || 'console.assert'}`;
scope.setExtra('arguments', normalize(args.slice(1), 3));
hub.captureMessage(message);
}
} else {
hub.captureMessage(message);
}
this.client.withScope((scope:Scope) => {
this.setupContext(scope);
this.client.captureMessage(msg, Severity.fromString(severity));
});
}