Skip to content

Commit

Permalink
Drop Transactions from Blocked User Agents (#2372)
Browse files Browse the repository at this point in the history
Update Sentry config to block certain user agents, and stop using deprecated options.
  • Loading branch information
nicholas-codecov authored Nov 2, 2023
1 parent 187da8a commit 581c691
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ const deClutterConfig = {

export const SentryRoute = Sentry.withSentryRouting(Route)

const checkForBlockedUserAgents = () => {
const userAgents = ['Bytespider']

return userAgents.some((agent) =>
window?.navigator?.userAgent.includes(agent)
)
}

export const setupSentry = ({
history,
}: {
Expand All @@ -61,13 +69,7 @@ export const setupSentry = ({
tracePropagationTargets: ['api.codecov.io', 'stage-api.codecov.dev'],
})

const replay = new Replay({
// Capture 10% of all sessions
sessionSampleRate: config?.SENTRY_SESSION_SAMPLE_RATE,

// Of the remaining 90% of sessions, if an error happens start capturing
errorSampleRate: config?.SENTRY_ERROR_SAMPLE_RATE,
})
const replay = new Replay()

return Sentry.init({
dsn: config.SENTRY_DSN,
Expand All @@ -76,8 +78,19 @@ export const setupSentry = ({
environment: config.SENTRY_ENVIRONMENT,
integrations: [browserTracing, replay],
tracesSampleRate: config?.SENTRY_TRACING_SAMPLE_RATE,
// Capture 10% of all sessions
replaysSessionSampleRate: config?.SENTRY_SESSION_SAMPLE_RATE,
// Of the remaining 90% of sessions, if an error happens start capturing
replaysOnErrorSampleRate: config?.SENTRY_ERROR_SAMPLE_RATE,
beforeSend: (event, _hint) => {
if (window?.navigator?.userAgent?.includes('Bytespider')) {
if (checkForBlockedUserAgents()) {
return null
}

return event
},
beforeSendTransaction: (event, _hint) => {
if (checkForBlockedUserAgents()) {
return null
}

Expand Down

0 comments on commit 581c691

Please sign in to comment.