2020-03-31 05:12:46 -04:00
|
|
|
// Conditionally enable Sentry based on whether the DSN token is set
|
|
|
|
if (window.ExposedSettings.sentryDsn) {
|
|
|
|
import(/* webpackChunkName: "sentry" */ '@sentry/browser').then(Sentry => {
|
2020-04-08 04:35:01 -04:00
|
|
|
let eventCount = 0
|
|
|
|
|
2020-03-31 05:12:46 -04:00
|
|
|
Sentry.init({
|
|
|
|
dsn: window.ExposedSettings.sentryDsn,
|
|
|
|
|
|
|
|
// Ignore errors unless they come from overleaf.com/sharelatex.com
|
|
|
|
// Adapted from: https://docs.sentry.io/platforms/javascript/#decluttering-sentry
|
|
|
|
whitelistUrls: [
|
|
|
|
/https:\/\/[a-z]+\.overleaf\.com/,
|
|
|
|
/https:\/\/[a-z]+\.sharelatex\.com/
|
2020-04-08 04:35:01 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
ignoreErrors: [
|
|
|
|
// Ignore very noisy error
|
|
|
|
'SecurityError: Permission denied to access property "pathname" on cross-origin object'
|
|
|
|
],
|
|
|
|
|
|
|
|
beforeSend(event) {
|
|
|
|
// Limit number of events sent to Sentry to 100 events "per page load",
|
|
|
|
// (i.e. the cap will be reset if the page is reloaded). This prevent
|
|
|
|
// hitting their server-side event cap.
|
|
|
|
eventCount++
|
|
|
|
if (eventCount > 100) {
|
|
|
|
return null // Block the event from sending
|
|
|
|
} else {
|
|
|
|
return event
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Sentry.configureScope(scope => {
|
|
|
|
if (window.user_id.length) {
|
|
|
|
scope.setUser(window.user_id)
|
|
|
|
}
|
2020-03-31 05:12:46 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
// Previously Raven added itself as a global, so we mimic that old behaviour
|
|
|
|
window.Raven = Sentry
|
|
|
|
})
|
|
|
|
}
|