File size: 1,533 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as Sentry from "@sentry/bun";

if (process.env.NODE_ENV === "production" && process.env.SENTRY_DSN) {
  Sentry.init({
    dsn: process.env.SENTRY_DSN,

    release: process.env.GIT_COMMIT_SHA || process.env.RAILWAY_GIT_COMMIT_SHA,

    // Use Railway environment name so staging and production are separate in Sentry
    environment:
      process.env.RAILWAY_ENVIRONMENT_NAME ||
      process.env.NODE_ENV ||
      "production",

    integrations: [Sentry.consoleLoggingIntegration({ levels: ["error"] })],

    sendDefaultPii: true,
    enableLogs: true,

    // Sample 10% of transactions for performance monitoring
    tracesSampleRate: 0.1,

    // Drop noisy transactions that don't provide value
    beforeSendTransaction(event) {
      const url = event.request?.url || event.transaction || "";

      if (
        url.includes("/health") ||
        url.includes("/openapi") ||
        event.request?.method === "OPTIONS"
      ) {
        return null;
      }

      return event;
    },

    // Filter out expected client errors from error reporting
    beforeSend(event) {
      // Don't send network/timeout errors from health checks
      const message = event.exception?.values?.[0]?.value || "";
      if (message.includes("ECONNREFUSED") || message.includes("ETIMEDOUT")) {
        // Only drop if it's from a health check context
        const transaction = event.transaction || "";
        if (transaction.includes("/health")) {
          return null;
        }
      }

      return event;
    },
  });
}