-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathconsole.ts
36 lines (32 loc) · 964 Bytes
/
console.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as util from 'node:util';
import { addBreadcrumb, defineIntegration, getClient } from '@sentry/core';
import type { IntegrationFn } from '@sentry/types';
import { addConsoleInstrumentationHandler, severityLevelFromString } from '@sentry/utils';
const INTEGRATION_NAME = 'Console';
const _consoleIntegration = (() => {
return {
name: INTEGRATION_NAME,
setup(client) {
addConsoleInstrumentationHandler(({ args, level }) => {
if (getClient() !== client) {
return;
}
addBreadcrumb(
{
category: 'console',
level: severityLevelFromString(level),
message: util.format.apply(undefined, args),
},
{
input: [...args],
level,
},
);
});
},
};
}) satisfies IntegrationFn;
/**
* Capture console logs as breadcrumbs.
*/
export const consoleIntegration = defineIntegration(_consoleIntegration);