-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsentry.client.config.ts
More file actions
156 lines (131 loc) · 4.7 KB
/
Copy pathsentry.client.config.ts
File metadata and controls
156 lines (131 loc) · 4.7 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Sentry Client Configuration
*
* REQ-0024 / CR-0003 — @sentry/nextjs v10.x (not v11). Init/Replay/sample rates unchanged.
* Error tracking and performance monitoring for client-side.
*/
import * as Sentry from "@sentry/nextjs";
/**
* Suppress Sentry console logs for network failures and ad blockers
*/
function suppressSentryConsoleErrors(): void {
if (typeof window === "undefined") return;
// Store original console methods
const originalError = console.error;
const originalWarn = console.warn;
const originalLog = console.log;
// Override console.error to filter Sentry errors
console.error = (...args: unknown[]) => {
const errorMessage = String(args[0] || "");
// Suppress Sentry transport errors
if (
errorMessage.includes("Sentry Logger") &&
(errorMessage.includes("Failed to fetch") ||
errorMessage.includes("Encountered error running transport") ||
errorMessage.includes("Error while sending envelope") ||
errorMessage.includes("ERR_BLOCKED_BY_CLIENT") ||
errorMessage.includes("network_error"))
) {
// Silently ignore - these are expected with ad blockers
return;
}
// Call original console.error for other errors
originalError.apply(console, args);
};
// Override console.warn to filter Sentry warnings
console.warn = (...args: unknown[]) => {
const warnMessage = String(args[0] || "");
// Suppress Sentry warnings related to blocked requests
if (
warnMessage.includes("Sentry Logger") &&
(warnMessage.includes("Failed to fetch") ||
warnMessage.includes("Discarded session") ||
warnMessage.includes("missing or non-string release"))
) {
// Silently ignore - these are expected with ad blockers
return;
}
// Call original console.warn for other warnings
originalWarn.apply(console, args);
};
// Override console.log to filter Sentry debug logs (only in production)
if (process.env.NODE_ENV === "production") {
console.log = (...args: unknown[]) => {
const logMessage = String(args[0] || "");
// Suppress Sentry debug logs in production
if (logMessage.includes("Sentry Logger")) {
// Silently ignore Sentry debug logs in production
return;
}
// Call original console.log for other logs
originalLog.apply(console, args);
};
}
}
// Suppress Sentry console errors before initialization
suppressSentryConsoleErrors();
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
// Disable debug logging to reduce console noise
debug: false,
// Replay can be used to record user sessions
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
// Filter out common errors that aren't actionable
ignoreErrors: [
// Browser extensions
"ResizeObserver loop limit exceeded",
"Non-Error promise rejection captured",
// Network errors that are user-related (ad blockers, network issues)
"NetworkError",
"Failed to fetch",
"TypeError: Failed to fetch",
"ERR_BLOCKED_BY_CLIENT",
"net::ERR_BLOCKED_BY_CLIENT",
// PostHog errors (handled separately)
"PostHog.js",
"[PostHog.js]",
],
// Filter out errors before sending to Sentry
beforeSend(event, hint) {
// Filter out network errors from ad blockers
const error = hint.originalException;
const errorMessage = error instanceof Error ? error.message : String(error || "");
// Ignore network errors that are likely from ad blockers
if (
errorMessage.includes("Failed to fetch") ||
errorMessage.includes("ERR_BLOCKED_BY_CLIENT") ||
errorMessage.includes("net::ERR_BLOCKED_BY_CLIENT") ||
errorMessage.includes("NetworkError") ||
(event.exception?.values?.[0]?.value?.includes("Failed to fetch")) ||
(event.exception?.values?.[0]?.type === "TypeError" &&
errorMessage.includes("fetch"))
) {
// Return null to prevent sending to Sentry
return null;
}
// Filter out PostHog-related errors
if (
errorMessage.includes("PostHog") ||
errorMessage.includes("[PostHog.js]") ||
(event.tags?.posthog_error)
) {
return null;
}
return event;
},
// Set environment
environment: process.env.NODE_ENV || "development",
// Release tracking (can be set via environment variable)
release: process.env.NEXT_PUBLIC_SENTRY_RELEASE,
// Suppress transport errors from showing in console
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration({
maskAllText: false,
blockAllMedia: false,
}),
],
});