-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathconsole.ts
33 lines (30 loc) · 869 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
import * as util from 'node:util';
import { addBreadcrumb, defineIntegration, getClient } from '@sentry/core';
import { addConsoleInstrumentationHandler, severityLevelFromString, truncate } from '@sentry/utils';
const INTEGRATION_NAME = 'Console';
/**
* Capture console logs as breadcrumbs.
*/
export const consoleIntegration = defineIntegration(() => {
return {
name: INTEGRATION_NAME,
setup(client) {
addConsoleInstrumentationHandler(({ args, level }) => {
if (getClient() !== client) {
return;
}
addBreadcrumb(
{
category: 'console',
level: severityLevelFromString(level),
message: truncate(util.format.apply(undefined, args), 2048), // 2KB
},
{
input: [...args],
level,
},
);
});
},
};
});