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;
}
}
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,
});
}
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);
}
});
}
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);
}
});
public setContext(name: string, context: { [key: string]: any } | null): this {
this._context[name] = context ? normalize(context) : undefined;
this._notifyScopeListeners();
return this;
}
public setTags(tags: { [key: string]: string }): this {
this._tags = {
...this._tags,
...normalize(tags),
};
this._notifyScopeListeners();
return this;
}
public enhanceEventWithErrorData(event: Event, hint?: EventHint): Event {
if (!hint || !hint.originalException || !isError(hint.originalException)) {
return event;
}
const name = (hint.originalException as ExtendedError).name || hint.originalException.constructor.name;
const errorData = this._extractErrorData(hint.originalException as ExtendedError);
if (errorData) {
let contexts = {
...event.contexts,
};
const normalizedErrorData = normalize(errorData, this._options.depth);
if (isPlainObject(normalizedErrorData)) {
contexts = {
...event.contexts,
[name]: {
...normalizedErrorData,
},
};
}
return {
...event,
contexts,
};
}
return event;
public addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this {
const timestamp = timestampWithMs();
const mergedBreadcrumb = { timestamp, ...breadcrumb };
this._breadcrumbs =
maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
? [...this._breadcrumbs, normalize(mergedBreadcrumb)].slice(-maxBreadcrumbs)
: [...this._breadcrumbs, normalize(mergedBreadcrumb)];
this._notifyScopeListeners();
return this;
}
public setExtras(extra: { [key: string]: any }): this {
this._extra = {
...this._extra,
...normalize(extra),
};
this._notifyScopeListeners();
return this;
}
public setUser(user: User | null): this {
this._user = normalize(user);
this._notifyScopeListeners();
return this;
}