/
init.js
83 lines (76 loc) · 2.45 KB
/
init.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// store references to original, unwrapped built-ins in order to:
// - get a clean, unwrapped setTimeout (so stack traces don't include frames from mocha)
// - make assertions re: wrapped functions
var originalBuiltIns = {
setTimeout: setTimeout,
setInterval: setInterval,
requestAnimationFrame: requestAnimationFrame,
xhrProtoOpen: XMLHttpRequest.prototype.open,
headAddEventListener: document.head.addEventListener, // use <head> 'cause body isn't closed yet
headRemoveEventListener: document.head.removeEventListener,
consoleDebug: console.debug,
consoleInfo: console.info,
consoleWarn: console.warn,
consoleError: console.error,
consoleLog: console.log,
};
var events = [];
var eventHints = [];
var breadcrumbs = [];
var breadcrumbHints = [];
// Oh dear IE10...
var dsn =
document.location.protocol +
"//public@" +
document.location.hostname +
(document.location.port ? ":" + document.location.port : "") +
"/1";
function initSDK() {
Sentry.init({
dsn: dsn,
integrations: [new Sentry.Integrations.Dedupe()],
attachStacktrace: true,
ignoreErrors: ["ignoreErrorTest"],
denyUrls: ["foo.js"],
beforeSend: function(event, eventHint) {
events.push(event);
eventHints.push(eventHint);
return event;
},
beforeBreadcrumb: function(breadcrumb, breadcrumbHint) {
// Filter console logs as we use them for debugging *a lot* and they are not *that* important
// But allow then if we explicitly say so (for one of integration tests)
if (
breadcrumb.category === "console" &&
!window.allowConsoleBreadcrumbs
) {
return null;
}
// One of the tests use manually created breadcrumb without eventId and we want to let it through
if (
breadcrumb.category.indexOf("sentry" === 0) &&
breadcrumb.event_id &&
!window.allowSentryBreadcrumbs
) {
return null;
}
if (
breadcrumb.type === "http" &&
(breadcrumb.data.url.indexOf("test.js") !== -1 ||
breadcrumb.data.url.indexOf("frame.html") !== -1)
) {
return null;
}
// Filter "refresh" like navigation which occurs in Mocha when testing on Android 4
if (
breadcrumb.category === "navigation" &&
breadcrumb.data.to === breadcrumb.data.from
) {
return null;
}
breadcrumbs.push(breadcrumb);
breadcrumbHints.push(breadcrumbHint);
return breadcrumb;
},
});
}