-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentry.client.config.ts
111 lines (96 loc) · 3.76 KB
/
sentry.client.config.ts
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
// This file configures the initialization of Sentry on the client.
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import { ExtraErrorData } from '@sentry/integrations'
import * as Sentry from '@sentry/nextjs'
import { getIsSupportedBrowser, maybeDetectBrowser } from './maybeDetectBrowser'
import { NEXT_PUBLIC_ENVIRONMENT } from '@/utils/shared/sharedEnv'
import { toBool } from '@/utils/shared/toBool'
const dsn = process.env.NEXT_PUBLIC_SENTRY_DSN
const COMMON_ERROR_MESSAGES_TO_GROUP = ['No internet connection detected']
const COMMON_TRANSACTION_NAMES_TO_GROUP = ['node_modules/thirdweb']
const isSupportedBrowser = getIsSupportedBrowser(maybeDetectBrowser())
Sentry.init({
environment: NEXT_PUBLIC_ENVIRONMENT,
dsn,
tracesSampleRate: NEXT_PUBLIC_ENVIRONMENT === 'production' ? 0.1 : 1.0,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
normalizeDepth: 10,
// replaysOnErrorSampleRate: 1.0,
// // This sets the sample rate to be 10%. You may want this to be 100% while
// // in development and sample at a lower rate in production
// replaysSessionSampleRate: 0.001,
// You can remove this option if you're not planning to use the Sentry Session Replay feature:
integrations: [new ExtraErrorData({ depth: 10 }), Sentry.replayIntegration()],
denyUrls: [
/vitals\.vercel-analytics\.com/i,
// Chrome extensions
/chrome-extension:\//i,
/extensions\//i,
/^chrome:\/\//i,
/inject/i,
],
replaysSessionSampleRate: 0,
replaysOnErrorSampleRate: 1.0,
ignoreErrors: [
`Can't find variable: bytecode`,
'ResizeObserver loop limit exceeded',
'ResizeObserver loop completed with undelivered notifications',
],
beforeSend: (event, hint) => {
// prevent local errors from triggering sentry
if (NEXT_PUBLIC_ENVIRONMENT === 'local') {
const shouldSuppress = toBool(process.env.SUPPRESS_SENTRY_ERRORS_ON_LOCAL) || !dsn
console.error(
`${shouldSuppress ? 'Suppressed ' : ''}Sentry`,
hint?.originalException || hint?.syntheticException,
)
if (shouldSuppress) {
return null
}
}
// prevent legacy browsers from triggering sentry
if (!isSupportedBrowser) {
return null
}
// force group common transaction names
try {
const transaction = event.transaction
console.log('transaction name match against COMMON_TRANSACTION_NAMES_TO_GROUP', transaction)
if (transaction) {
COMMON_TRANSACTION_NAMES_TO_GROUP.forEach(message => {
if (transaction.indexOf(message) !== -1) {
event.fingerprint = [`forceGroupErrorTransaction-${message}`]
console.log(
`Sentry: Forced fingerprint to "${message}" transaction from "${transaction}"`,
)
}
})
}
} catch (e) {
console.error(e)
console.log('Sentry: Failed to force transaction fingerprint')
return event
}
// force group error names
try {
const error = hint.originalException as Error
const errorMessage = error?.message
console.log('error message to match against COMMON_ERROR_MESSAGES_TO_GROUP', errorMessage)
if (errorMessage) {
COMMON_ERROR_MESSAGES_TO_GROUP.forEach(message => {
if (errorMessage.indexOf(message) !== -1) {
event.fingerprint = [`forceGroupErrorMessage-${message}`]
console.log(`Sentry: Forced fingerprint to "${message}" message from "${errorMessage}"`)
}
})
}
} catch (e) {
console.error(e)
console.log('Sentry: Failed to force error message fingerprint')
return event
}
return event
},
})