Skip to content

Commit

Permalink
fix(sentry): add santization to transactions and add filtering for ch…
Browse files Browse the repository at this point in the history
…rome extension
  • Loading branch information
atticusofsparta committed Jan 12, 2024
1 parent 3f9a129 commit ee6d8fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
9 changes: 0 additions & 9 deletions src/components/layout/Notifications/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ export default function Notifications() {
function handleError(error: Error | { message: string; name: string }) {
// TODO: check for duplicate errors
if (error instanceof Error) {
if (
JSON.stringify(error.stack).includes(
'chrome-extension://aflkmfhebedbjioipglgcbcmnbpgliof/injected.js',
)
) {
// we want to ignore errors from this extension
// https://permanent-data-solutions-e7.sentry.io/issues/4774988645/?project=4504894571085824&query=is%3Aunresolved&referrer=issue-stream&statsPeriod=14d&stream_index=15
return;
}
const sentryID = Sentry.captureException(error);
console.debug('Error sent to sentry:', error, sentryID);
}
Expand Down
25 changes: 24 additions & 1 deletion src/utils/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,37 @@ const sentry =
tracesSampleRate: 1.0,
environment: ENVIRONMENT,
beforeSend(event) {
if (shouldFilterEvent(event)) {
return null;
}
return sanitizeEvent(event);
},
beforeSendTransaction(event) {
if (shouldFilterEvent(event)) {
return null;
}
return sanitizeEvent(event);
},
})
: {};

export default sentry;

const sanitizeEvent = (event: Sentry.Event): Sentry.Event => {
const filterMessages = new Set([
'chrome-extension://aflkmfhebedbjioipglgcbcmnbpgliof/injected.js',
]);

const shouldFilterEvent = (event: Sentry.Event): boolean => {
const isFiltered = [...filterMessages].some((message) =>
event.exception?.values?.some((value) =>
value.value?.includes(message.toLowerCase()),
),
);

return isFiltered;
};

const sanitizeEvent = (event: Sentry.Event): Sentry.Event | null => {
// Remove user's IP address
if (event.request) {
if (event.request.headers) {
Expand Down

0 comments on commit ee6d8fb

Please sign in to comment.