Last active
December 8, 2020 15:01
-
-
Save martinsvoboda/ea7fcfa30683c1220a6370b6867bbefe to your computer and use it in GitHub Desktop.
Superlazy Sentry integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* Dynamically load Sentry only when error is reported */ | |
/* Similar to https://docs.sentry.io/platforms/javascript/install/lazy-load-sentry/ */ | |
function log_to_sentry(e, url, line, column, error) { | |
if (!window.Sentry) { | |
var script = document.createElement('script'); | |
script.src = "https://browser.sentry-cdn.com/5.29.0/bundle.min.js"; | |
script.integrity="sha384-/dYT/04VSU9ItKRPTkWeVZ0kqRsVh/T/5rNCjzBwpx7sYeeueKgJzGMNXSal3xoo"; | |
script.crossOrigin = "anonymous"; | |
script.onload = function () { | |
Sentry.init({ | |
dsn: "https://XXXXXX.ingest.sentry.io/XXXXXX", | |
}); | |
Sentry.captureException(e); | |
}; | |
document.head.appendChild(script); | |
} | |
} | |
window.addEventListener('error', function (e) { | |
log_to_sentry(e); | |
}); | |
window.addEventListener('unhandledrejection', function (e) { | |
log_to_sentry(e.reason); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment