sentry.js 1.4 KB

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