Skip to content

Commit

Permalink
[v7] Attach correct data to scope in CatureConsole integration
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Mar 23, 2021
1 parent 7bde003 commit 320d1f0
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions packages/integration-common-captureconsole/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientLike, Integration, ScopeContext, Severity } from '@sentry/types';
import { ClientLike, Integration, Severity } from '@sentry/types';
import { fill, getGlobalObject, safeJoin } from '@sentry/utils';

type Level = typeof LEVELS[number];
Expand Down Expand Up @@ -29,30 +29,20 @@ export class CaptureConsole implements Integration {
return;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
fill(global.console, level, (originalConsoleLevel: () => unknown) => (...args: unknown[]): void => {
const scope: ScopeContext = {
level: Severity.fromString(level),
extra: {
arguments: args,
},
};

// TODO: Allow capture methods to accept a Scope instance so we can use things like
// `const scope = client.getScope().clone();` to mimick `withScope` per-client?
// scope.addEventProcessor(event => {
// event.logger = 'console';
// return event;
// });
const scope = client.getScope().clone();
scope.setLevel(Severity.fromString(level));
scope.setExtra('arguments', args);
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.extra = {
...scope.extra,
arguments: args.slice(1),
};
scope.setExtra('arguments', args.slice(1));
client.captureMessage(message, { scope });
}
} else {
Expand Down

0 comments on commit 320d1f0

Please sign in to comment.