Repository navigation
Expand file tree
/
Copy pathdebug.ts
More file actions
72 lines (64 loc) · 2.14 KB
/
Copy pathdebug.ts
File metadata and controls
72 lines (64 loc) · 2.14 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Client, Event, EventHint, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';
const INTEGRATION_NAME = 'Debug';
interface DebugOptions {
/** Controls whether console output created by this integration should be stringified. Default: `false` */
stringify?: boolean;
/** Controls whether a debugger should be launched before an event is sent. Default: `false` */
debugger?: boolean;
}
const _debugIntegration = ((options: DebugOptions = {}) => {
const _options = {
debugger: false,
stringify: false,
...options,
};
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client) {
if (!client.on) {
return;
}
client.on('beforeSendEvent', (event: Event, hint?: EventHint) => {
if (_options.debugger) {
// eslint-disable-next-line no-debugger
debugger;
}
/* eslint-disable no-console */
consoleSandbox(() => {
if (_options.stringify) {
console.log(JSON.stringify(event, null, 2));
if (hint && Object.keys(hint).length) {
console.log(JSON.stringify(hint, null, 2));
}
} else {
console.log(event);
if (hint && Object.keys(hint).length) {
console.log(hint);
}
}
});
/* eslint-enable no-console */
});
},
};
}) satisfies IntegrationFn;
export const debugIntegration = defineIntegration(_debugIntegration);
/**
* Integration to debug sent Sentry events.
* This integration should not be used in production.
*
* @deprecated Use `debugIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const Debug = convertIntegrationFnToClass(INTEGRATION_NAME, debugIntegration) as IntegrationClass<
Integration & { setup: (client: Client) => void }
> & {
new (options?: {
stringify?: boolean;
debugger?: boolean;
}): Integration;
};