sentry.config.base.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as Sentry from '@sentry/nextjs';
  2. import { getSentryUserID } from '@ente/shared/sentry/utils';
  3. import { runningInBrowser } from '@ente/shared/platform';
  4. import { getHasOptedOutOfCrashReports } from '@ente/shared/storage/localStorage/helpers';
  5. import { isDevBuild } from '@ente/shared/network/api';
  6. export const initSentry = async (dsn: string) => {
  7. // Don't initialize Sentry on dev builds
  8. if (isDevBuild) return;
  9. // Don't initialize Sentry if the user has opted out of crash reporting
  10. if (optedOut()) return;
  11. Sentry.init({
  12. dsn,
  13. release: process.env.GIT_SHA,
  14. attachStacktrace: true,
  15. autoSessionTracking: false,
  16. tunnel: 'https://sentry-reporter.ente.io',
  17. beforeSend(event) {
  18. event.request = event.request || {};
  19. const currentURL = new URL(document.location.href);
  20. currentURL.hash = '';
  21. event.request.url = currentURL.href;
  22. return event;
  23. },
  24. integrations: function (i) {
  25. return i.filter(function (i) {
  26. return i.name !== 'Breadcrumbs';
  27. });
  28. },
  29. });
  30. Sentry.setUser({ id: await getSentryUserID() });
  31. };
  32. /** Return true if the user has opted out of crash reporting */
  33. const optedOut = () => runningInBrowser() && getHasOptedOutOfCrashReports();