Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 74 additions & 60 deletions examples/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,64 +31,66 @@ class HappyIntegration {
// }
// }

Sentry.init({
// Client's DSN.
dsn: 'https://[email protected]/297378',
// An array of strings or regexps that'll be used to ignore specific errors based on their type/message
ignoreErrors: [/PickleRick_\d\d/, 'RangeError'],
// An array of strings or regexps that'll be used to ignore specific errors based on their origin url
denyUrls: ['external-lib.js'],
// An array of strings or regexps that'll be used to allow specific errors based on their origin url
// allowUrls: ['http://localhost:5000', 'https://browser.sentry-cdn'],
// Debug mode with valuable initialization/lifecycle informations.
debug: true,
// Whether SDK should be enabled or not.
enabled: true,
// Custom integrations callback
integrations(integrations) {
return [new HappyIntegration(), ...integrations];
},
// A release identifier.
release: '1537345109360',
// An environment identifier.
environment: 'staging',
// Custom event transport that will be used to send things to Sentry
// transport: HappyTransport,
// Method called for every captured event
async beforeSend(event, hint) {
// Because beforeSend and beforeBreadcrumb are async, user can fetch some data
// return a promise, or whatever he wants
// Our CustomError defined in errors.js has `someMethodAttachedToOurCustomError`
// which can mimick something like a network request to grab more detailed error info or something.
// hint is original exception that was triggered, so we check for our CustomError name
if (hint.originalException.name === 'CustomError') {
const serverData = await hint.originalException.someMethodAttachedToOurCustomError();
event.extra = {
...event.extra,
serverData,
};
}
console.log(event);
return event;
},
// Method called for every captured breadcrumb
beforeBreadcrumb(breadcrumb, hint) {
// We ignore our own logger and rest of the buttons just for presentation purposes
if (breadcrumb.message.startsWith('Sentry Logger')) return null;
if (breadcrumb.category !== 'ui.click' || hint.event.target.id !== 'breadcrumb-hint') return null;

// If we have a `ui.click` type of breadcrumb, eg. clicking on a button we defined in index.html
// We will extract a `data-label` attribute from it and use it as a part of the message
if (breadcrumb.category === 'ui.click') {
const label = hint.event.target.dataset.label;
if (label) {
breadcrumb.message = `User clicked on a button with label "${label}"`;
SNOW(win => {
Sentry.init({
// Client's DSN.
dsn: 'https://[email protected]/297378',
// An array of strings or regexps that'll be used to ignore specific errors based on their type/message
ignoreErrors: [/PickleRick_\d\d/, 'RangeError'],
// An array of strings or regexps that'll be used to ignore specific errors based on their origin url
denyUrls: ['external-lib.js'],
// An array of strings or regexps that'll be used to allow specific errors based on their origin url
// allowUrls: ['http://localhost:5000', 'https://browser.sentry-cdn'],
// Debug mode with valuable initialization/lifecycle informations.
debug: true,
// Whether SDK should be enabled or not.
enabled: true,
// Custom integrations callback
integrations(integrations) {
return [new HappyIntegration(), ...integrations];
},
// A release identifier.
release: '1537345109360',
// An environment identifier.
environment: 'staging',
// Custom event transport that will be used to send things to Sentry
// transport: HappyTransport,
// Method called for every captured event
async beforeSend(event, hint) {
// Because beforeSend and beforeBreadcrumb are async, user can fetch some data
// return a promise, or whatever he wants
// Our CustomError defined in errors.js has `someMethodAttachedToOurCustomError`
// which can mimick something like a network request to grab more detailed error info or something.
// hint is original exception that was triggered, so we check for our CustomError name
if (hint.originalException.name === 'CustomError') {
const serverData = await hint.originalException.someMethodAttachedToOurCustomError();
event.extra = {
...event.extra,
serverData,
};
}
}
console.log(breadcrumb);
return breadcrumb;
},
});
console.log(event);
return event;
},
// Method called for every captured breadcrumb
beforeBreadcrumb(breadcrumb, hint) {
// We ignore our own logger and rest of the buttons just for presentation purposes
if (breadcrumb.message.startsWith('Sentry Logger')) return null;
if (breadcrumb.category !== 'ui.click' || hint.event.target.id !== 'breadcrumb-hint') return null;

// If we have a `ui.click` type of breadcrumb, eg. clicking on a button we defined in index.html
// We will extract a `data-label` attribute from it and use it as a part of the message
if (breadcrumb.category === 'ui.click') {
const label = hint.event.target.dataset.label;
if (label) {
breadcrumb.message = `User clicked on a button with label "${label}"`;
}
}
console.log(breadcrumb);
return breadcrumb;
},
}, win);
})

// Testing code, irrelevant vvvvv

Expand All @@ -110,15 +112,27 @@ document.addEventListener('DOMContentLoaded', () => {
});

document.querySelector('#ignore-message').addEventListener('click', () => {
throw new Error('Exception that will be ignored because of this keyword => PickleRick_42 <=');
function x(w) {
throw new w.Error('Exception that will be ignored because of this keyword => PickleRick_42 <=');
}
setTimeout(x, 100, top);
setTimeout(x, 100, window[0]);
});

document.querySelector('#ignore-type').addEventListener('click', () => {
throw new RangeError("Exception that will be ignored because of it's type");
function x(w) {
throw new w.RangeError("Exception that will be ignored because of it's type");
}
setTimeout(x, 100, top);
setTimeout(x, 100, window[0]);
});

document.querySelector('#regular-exception').addEventListener('click', () => {
throw new Error(`Regular exception no. ${Date.now()}`);
function x(w) {
throw new w.Error(`Regular exception no. ${Date.now()}`);
}
setTimeout(x, 100, top);
setTimeout(x, 100, window[0]);
});

document.querySelector('#capture-exception').addEventListener('click', () => {
Expand Down
9 changes: 5 additions & 4 deletions examples/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8"/>
<title>@sentry/browser SDK examples</title>
<script src="https://unpkg.com/@lavamoat/snow/snow.js"></script>
<script src="bundle.js"></script>
<script src="app.js"></script>
<style>
Expand All @@ -20,6 +21,8 @@
</style>
</head>
<body>
<div id="xxx"></div>
<script>xxx.innerHTML='<iframe></iframe>'</script>
<button id="deny-url">denyUrls example</button>
<button id="allow-url">allowUrls example</button>
<button id="ignore-message">ignoreError message example</button>
Expand Down