-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsentry.js
50 lines (48 loc) · 1.29 KB
/
sentry.js
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
let Sentry;
if (process.browser) {
Sentry = require("@sentry/browser");
if (!window.sentryHub) {
window.sentryHub = __SENTRY_HUB__;
}
} else {
Sentry = require("@sentry/node");
if (!global.sentryHub) {
global.sentryHub = __SENTRY_HUB__;
}
}
let hub = sentryHub;
const federatedSentry = (options) => {
const name = options.name;
delete options.name;
if (typeof window !== "undefined") {
options.beforeSend = (event) => {
const request = {
url: window.location.href,
headers: { "User-Agent": navigator.userAgent },
};
if (event.request) {
Object.assign(event.request, request);
} else {
event.request = request;
}
return event;
};
}
console.log("create federated sentry", name);
if (!hub[name]) {
const client = process.browser
? new Sentry.BrowserClient(options)
: new Sentry.NodeClient(options);
hub[name] = new Sentry.Hub(client);
}
};
const captureException = (exception, host = process.env.CURRENT_HOST) => {
try {
// try and send error to the hub
hub[host].captureException(exception);
} catch {
// if hub isnt registered, send error to global handler, if exists
Sentry.captureException(exception);
}
};
module.exports = { federatedSentry, captureException };