Repository navigation
Expand file tree
/
Copy pathtest-code.js
More file actions
83 lines (74 loc) · 2.19 KB
/
Copy pathtest-code.js
File metadata and controls
83 lines (74 loc) · 2.19 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
75
76
77
78
79
80
81
82
83
/* eslint-disable no-console */
const Sentry = require('../../build/npm/cjs/index.js');
const Integrations = require('../../../integrations/build/npm/cjs/dedupe.js');
// Init
Sentry.init({
dsn: 'https://completelyrandom@dsn.asdf/42',
integrations: [new Integrations.Dedupe()],
beforeSend(_event) {
console.log('Got an event');
return null;
},
beforeBreadcrumb(crumb) {
console.log(`Got a breadcrumb: ${crumb.category}`);
return crumb;
},
});
// Configure
Sentry.configureScope(scope => {
scope.setExtra('foo', 'bar');
scope.setFingerprint('foo');
scope.setLevel('warning');
scope.setTag('foo', 'bar');
scope.setUser('foo', 'bar');
});
// Breadcrumbs integration
window.console.log('Console', 'Breadcrumb');
window.console.error({ foo: 'bar' });
const clickEvent = new MouseEvent('click');
const clickElement = window.document.createElement('button');
clickElement.addEventListener('click', () => {
// do nothing, just capture a breadcrumb
});
clickElement.dispatchEvent(clickEvent);
const keypressEvent = new KeyboardEvent('keypress');
const keypressElement = window.document.createElement('input');
keypressElement.addEventListener('keypress', () => {
// do nothing, just capture a breadcrumb
});
keypressElement.dispatchEvent(keypressEvent);
// Basic breadcrumb
Sentry.addBreadcrumb({
category: 'basic',
message: 'crumb',
});
// Capture methods
Sentry.captureException(new Error('foo'));
Sentry.captureException(new Error('foo'), {
tags: {
foo: 1,
},
});
Sentry.captureException(new Error('foo'), scope => scope);
Sentry.captureMessage('bar');
Sentry.captureMessage('bar', {
tags: {
foo: 1,
},
});
Sentry.captureMessage('bar', scope => scope);
// Scope behavior
Sentry.withScope(scope => {
scope.setExtra('baz', 'qux');
scope.setFingerprint('baz');
scope.setLevel('error');
scope.setTag('baz', 'qux');
scope.setUser('baz', 'qux');
Sentry.captureException(new TypeError('bar'));
Sentry.captureMessage('baz');
});
var xhr = new XMLHttpRequest();
xhr.onload = () => console.log('loaded'); // This throws error
// xhr.addEventListener("load", () => console.log('loaded')); This does not throw error
xhr.open('GET', 'https://httpbin.org/get');
xhr.send();