-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsentry.js
More file actions
74 lines (65 loc) · 1.47 KB
/
sentry.js
File metadata and controls
74 lines (65 loc) · 1.47 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
73
74
import { getPluginNames } from './plugin.js';
const GUEST = {
id: 0,
username: 'Guest',
};
function invalid() {
return typeof Sentry === 'undefined';
}
export function init() {
if (invalid()) return;
const config = {
dsn: '__SENTRY__',
release: 'underscript@__VERSION__',
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
environment: '__ENVIRONMENT__',
initialScope: {
tags: {
underscript: true,
},
user: GUEST,
},
};
Sentry.init(config);
}
function setUser(data) {
if (invalid()) return;
Sentry.configureScope((scope) => {
scope.setUser(data);
});
}
function capture(error, event, plugin) {
if (invalid()) return;
Sentry.withScope((scope) => {
if (plugin) {
scope.setTag('plugin', plugin.name);
scope.setTag('underscript', null);
}
if (event) {
scope.setContext('event', event);
}
const plugins = getPluginNames();
if (plugins.length) {
scope.setContext('plugins', plugins);
}
if (error instanceof Error) {
Sentry.captureException(error);
} else {
Sentry.captureMessage(error);
}
});
}
export function login(id = '', username = '') {
if (!id) return;
setUser({ id, username });
}
export function logout() {
setUser(GUEST);
}
export function captureError(error, event = undefined) {
capture(error, event);
}
export function capturePluginError(plugin, error, event = undefined) {
capture(error, event, plugin);
}