sentry.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Conditionally enable Sentry based on whether the DSN token is set
  2. // Conditionally enable Sentry based on whether the DSN token is set
  3. if (window.ExposedSettings.sentryDsn) {
  4. import(/* webpackChunkName: "sentry" */ '@sentry/browser').then(Sentry => {
  5. let eventCount = 0
  6. Sentry.init({
  7. dsn: window.ExposedSettings.sentryDsn,
  8. release: window.ExposedSettings.sentryRelease,
  9. environment: window.ExposedSettings.sentryEnvironment,
  10. // Ignore errors unless they come from our origins
  11. // Adapted from: https://docs.sentry.io/platforms/javascript/#decluttering-sentry
  12. whitelistUrls: [
  13. new RegExp(window.ExposedSettings.sentryAllowedOriginRegex)
  14. ],
  15. ignoreErrors: [
  16. // Ignore very noisy error
  17. 'SecurityError: Permission denied to access property "pathname" on cross-origin object',
  18. // Ignore unhandled error that is "expected" - see https://github.com/overleaf/issues/issues/3321
  19. /^Missing PDF/,
  20. // Ignore "expected" error from aborted fetch - see https://github.com/overleaf/issues/issues/3321
  21. /^AbortError/,
  22. // Ignore spurious error from Ace internals - see https://github.com/overleaf/issues/issues/3321
  23. 'ResizeObserver loop limit exceeded',
  24. 'ResizeObserver loop completed with undelivered notifications.'
  25. ],
  26. beforeSend(event) {
  27. // Limit number of events sent to Sentry to 100 events "per page load",
  28. // (i.e. the cap will be reset if the page is reloaded). This prevent
  29. // hitting their server-side event cap.
  30. eventCount++
  31. if (eventCount > 100) {
  32. return null // Block the event from sending
  33. } else {
  34. return event
  35. }
  36. }
  37. })
  38. Sentry.setUser({ id: window.user_id })
  39. // Previously Raven added itself as a global, so we mimic that old behaviour
  40. window.Raven = Sentry
  41. })
  42. }