sentry.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Conditionally enable Sentry based on whether the DSN token is set
  2. if (window.ExposedSettings.sentryDsn) {
  3. import(/* webpackChunkName: "sentry" */ '@sentry/browser').then(Sentry => {
  4. let eventCount = 0
  5. Sentry.init({
  6. dsn: window.ExposedSettings.sentryDsn,
  7. // Ignore errors unless they come from overleaf.com/sharelatex.com
  8. // Adapted from: https://docs.sentry.io/platforms/javascript/#decluttering-sentry
  9. whitelistUrls: [
  10. /https:\/\/[a-z]+\.overleaf\.com/,
  11. /https:\/\/[a-z]+\.sharelatex\.com/
  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.configureScope(scope => {
  30. if (window.user_id.length) {
  31. scope.setUser(window.user_id)
  32. }
  33. })
  34. // Previously Raven added itself as a global, so we mimic that old behaviour
  35. window.Raven = Sentry
  36. })
  37. }