sentry.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. // Ignore errors unless they come from our origins
  9. // Adapted from: https://docs.sentry.io/platforms/javascript/#decluttering-sentry
  10. whitelistUrls: [
  11. new RegExp(window.ExposedSettings.sentryAllowedOriginRegex)
  12. ],
  13. ignoreErrors: [
  14. // Ignore very noisy error
  15. 'SecurityError: Permission denied to access property "pathname" on cross-origin object'
  16. ],
  17. beforeSend(event) {
  18. // Limit number of events sent to Sentry to 100 events "per page load",
  19. // (i.e. the cap will be reset if the page is reloaded). This prevent
  20. // hitting their server-side event cap.
  21. eventCount++
  22. if (eventCount > 100) {
  23. return null // Block the event from sending
  24. } else {
  25. return event
  26. }
  27. }
  28. })
  29. Sentry.setUser({ id: window.user_id })
  30. // Previously Raven added itself as a global, so we mimic that old behaviour
  31. window.Raven = Sentry
  32. })
  33. }