Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-12818-changed-1757021047591.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@linode/manager': Changed
---

Ignore window.crypto.randomUUID error in Sentry config file ([#12818](https://github.com/linode/manager/pull/12818))
38 changes: 37 additions & 1 deletion packages/manager/src/initSentry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { normalizeErrorMessage } from './initSentry';
import { ErrorEvent } from '@sentry/react';

Check warning on line 1 in packages/manager/src/initSentry.test.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 All imports in the declaration are only used as types. Use `import type`. Raw Output: {"ruleId":"@typescript-eslint/consistent-type-imports","severity":1,"message":"All imports in the declaration are only used as types. Use `import type`.","line":1,"column":1,"nodeType":"ImportDeclaration","messageId":"typeOverValue","endLine":1,"endColumn":44,"fix":{"range":[6,6],"text":" type"}}

import { beforeSend, normalizeErrorMessage } from './initSentry';

import type { APIError } from '@linode/api-v4/lib/types';

Expand All @@ -21,3 +23,37 @@
expect(normalizeErrorMessage(null as any)).toBe('null');
});
});

describe('beforeSend', () => {
it('should return null when user agent contains Catchpoint', () => {
const mockSentryEvent: ErrorEvent = {
message: 'Some error occurred',

Check warning on line 30 in packages/manager/src/initSentry.test.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Define a constant instead of duplicating this literal 3 times. Raw Output: {"ruleId":"sonarjs/no-duplicate-string","severity":1,"message":"Define a constant instead of duplicating this literal 3 times.","line":30,"column":16,"nodeType":"Literal","endLine":30,"endColumn":37}
request: {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; Catchpoint)',
},
},
type: undefined,

Check warning on line 36 in packages/manager/src/initSentry.test.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Use null instead. Raw Output: {"ruleId":"sonarjs/no-undefined-assignment","severity":1,"message":"Use null instead.","line":36,"column":13,"nodeType":"Identifier","messageId":"useNull","endLine":36,"endColumn":22}
};

const result = beforeSend(mockSentryEvent);
expect(result).toBeNull();
});

it('should process normal events when user agent does not contain Catchpoint', () => {
const mockSentryEvent: ErrorEvent = {
message: 'Some error occurred',
request: {
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
},
},
type: undefined,

Check warning on line 52 in packages/manager/src/initSentry.test.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Use null instead. Raw Output: {"ruleId":"sonarjs/no-undefined-assignment","severity":1,"message":"Use null instead.","line":52,"column":13,"nodeType":"Identifier","messageId":"useNull","endLine":52,"endColumn":22}
};

const result = beforeSend(mockSentryEvent);
expect(result).not.toBeNull();
expect(result?.message).toBe('Some error occurred');
});
});
9 changes: 8 additions & 1 deletion packages/manager/src/initSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ export const initSentry = () => {
}
};

const beforeSend = (sentryEvent: SentryErrorEvent): null | SentryErrorEvent => {
export const beforeSend = (
sentryEvent: SentryErrorEvent
): null | SentryErrorEvent => {
const normalizedErrorMessage = normalizeErrorMessage(sentryEvent.message);

const userAgent = sentryEvent.request?.headers?.['User-Agent'];
if (userAgent?.includes('Catchpoint')) {
return null;
}

if (
errorsToIgnore.some((eachRegex) =>
Boolean(normalizedErrorMessage?.match(eachRegex))
Expand Down