2
0

sentry.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import * as Sentry from "@sentry/browser";
  2. import callsites from "callsites";
  3. const SentryEnvHostnameMap: { [key: string]: string } = {
  4. "excalidraw.com": "production",
  5. "staging.excalidraw.com": "staging",
  6. "vercel.app": "staging",
  7. };
  8. const SENTRY_DISABLED = import.meta.env.VITE_APP_DISABLE_SENTRY === "true";
  9. // Disable Sentry locally or inside the Docker to avoid noise/respect privacy
  10. const onlineEnv =
  11. !SENTRY_DISABLED &&
  12. Object.keys(SentryEnvHostnameMap).find(
  13. (item) => window.location.hostname.indexOf(item) >= 0,
  14. );
  15. Sentry.init({
  16. dsn: onlineEnv
  17. ? "https://[email protected]/5179260"
  18. : undefined,
  19. environment: onlineEnv ? SentryEnvHostnameMap[onlineEnv] : undefined,
  20. release: import.meta.env.VITE_APP_GIT_SHA,
  21. ignoreErrors: [
  22. "undefined is not an object (evaluating 'window.__pad.performLoop')", // Only happens on Safari, but spams our servers. Doesn't break anything
  23. "InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.", // Not much we can do about the IndexedDB closing error
  24. /(Failed to fetch|(fetch|loading) dynamically imported module)/i, // This is happening when a service worker tries to load an old asset
  25. /QuotaExceededError: (The quota has been exceeded|.*setItem.*Storage)/i, // localStorage quota exceeded
  26. "Internal error opening backing store for indexedDB.open", // Private mode and disabled indexedDB
  27. ],
  28. integrations: [
  29. Sentry.captureConsoleIntegration({
  30. levels: ["error"],
  31. }),
  32. ],
  33. beforeSend(event) {
  34. if (event.request?.url) {
  35. event.request.url = event.request.url.replace(/#.*$/, "");
  36. }
  37. if (!event.exception) {
  38. event.exception = {
  39. values: [
  40. {
  41. type: "ConsoleError",
  42. value: event.message ?? "Unknown error",
  43. stacktrace: {
  44. frames: callsites()
  45. .slice(1)
  46. .filter(
  47. (frame) =>
  48. frame.getFileName() &&
  49. !frame.getFileName()?.includes("@sentry_browser.js"),
  50. )
  51. .map((frame) => ({
  52. filename: frame.getFileName() ?? undefined,
  53. function: frame.getFunctionName() ?? undefined,
  54. in_app: !(
  55. frame.getFileName()?.includes("node_modules") ?? false
  56. ),
  57. lineno: frame.getLineNumber() ?? undefined,
  58. colno: frame.getColumnNumber() ?? undefined,
  59. })),
  60. },
  61. mechanism: {
  62. type: "instrument",
  63. handled: true,
  64. data: {
  65. function: "console.error",
  66. handler: "Sentry.beforeSend",
  67. },
  68. },
  69. },
  70. ],
  71. };
  72. }
  73. return event;
  74. },
  75. });