2020-12-03 08:58:46 -05:00
|
|
|
// Conditionally enable Sentry based on whether the DSN token is set
|
2022-04-22 06:42:57 -04:00
|
|
|
import getMeta from '../utils/meta'
|
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
const reporterPromise = window.ExposedSettings?.sentryDsn
|
2020-12-03 08:58:46 -05:00
|
|
|
? sentryReporter()
|
|
|
|
: nullReporter()
|
|
|
|
|
|
|
|
function sentryReporter() {
|
|
|
|
return (
|
|
|
|
import(/* webpackMode: "eager" */ '@sentry/browser')
|
|
|
|
.then(Sentry => {
|
|
|
|
let eventCount = 0
|
|
|
|
|
|
|
|
Sentry.init({
|
|
|
|
dsn: window.ExposedSettings.sentryDsn,
|
2021-08-18 10:55:50 -04:00
|
|
|
environment: window.ExposedSettings.sentryEnvironment,
|
2020-12-03 08:58:46 -05:00
|
|
|
release: window.ExposedSettings.sentryRelease,
|
2021-05-12 06:28:30 -04:00
|
|
|
autoSessionTracking: false,
|
2020-12-03 08:58:46 -05:00
|
|
|
|
|
|
|
// Ignore errors unless they come from our origins
|
|
|
|
// Adapted from: https://docs.sentry.io/platforms/javascript/#decluttering-sentry
|
|
|
|
whitelistUrls: [
|
2021-04-27 03:52:58 -04:00
|
|
|
new RegExp(window.ExposedSettings.sentryAllowedOriginRegex),
|
2020-12-03 08:58:46 -05:00
|
|
|
],
|
|
|
|
|
|
|
|
ignoreErrors: [
|
|
|
|
// Ignore very noisy error
|
|
|
|
'SecurityError: Permission denied to access property "pathname" on cross-origin object',
|
|
|
|
// Ignore unhandled error that is "expected" - see https://github.com/overleaf/issues/issues/3321
|
|
|
|
/^Missing PDF/,
|
2022-02-04 04:23:37 -05:00
|
|
|
/^pdfng error Error: MissingPDFException/,
|
2020-12-03 08:58:46 -05:00
|
|
|
// Ignore "expected" error from aborted fetch - see https://github.com/overleaf/issues/issues/3321
|
|
|
|
/^AbortError/,
|
|
|
|
// Ignore spurious error from Ace internals - see https://github.com/overleaf/issues/issues/3321
|
|
|
|
'ResizeObserver loop limit exceeded',
|
2021-04-27 03:52:58 -04:00
|
|
|
'ResizeObserver loop completed with undelivered notifications.',
|
2021-08-16 10:58:36 -04:00
|
|
|
// Microsoft Outlook SafeLink crawler
|
|
|
|
// https://forum.sentry.io/t/unhandledrejection-non-error-promise-rejection-captured-with-value/14062
|
|
|
|
/Non-Error promise rejection captured with value: Object Not Found Matching Id/,
|
2020-12-03 08:58:46 -05:00
|
|
|
],
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-12-03 08:58:46 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Sentry.setUser({ id: window.user_id })
|
|
|
|
|
2022-04-22 06:42:57 -04:00
|
|
|
const splitTestAssignments = getMeta('ol-splitTestVariants')
|
|
|
|
if (splitTestAssignments) {
|
|
|
|
for (const [name, value] of Object.entries(splitTestAssignments)) {
|
2022-04-26 05:37:22 -04:00
|
|
|
// Ensure Sentry tag name is within the 32-character limit
|
|
|
|
Sentry.setTag(`ol.${name}`.slice(0, 32), value.toString())
|
2022-04-22 06:42:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 08:58:46 -05:00
|
|
|
return Sentry
|
|
|
|
})
|
|
|
|
// If Sentry fails to load, use the null reporter instead
|
2021-05-12 06:28:30 -04:00
|
|
|
.catch(error => {
|
|
|
|
console.error(error)
|
|
|
|
return nullReporter()
|
|
|
|
})
|
2020-12-03 08:58:46 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function nullReporter() {
|
|
|
|
return Promise.resolve({
|
2021-06-09 09:45:55 -04:00
|
|
|
captureException: console.error,
|
|
|
|
captureMessage: console.error,
|
2020-12-03 08:58:46 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export function captureException(...args) {
|
|
|
|
reporterPromise.then(reporter => reporter.captureException(...args))
|
|
|
|
}
|
|
|
|
|
|
|
|
export function captureMessage(...args) {
|
|
|
|
reporterPromise.then(reporter => reporter.captureMessage(...args))
|
|
|
|
}
|