Skip to content

Commit 810c57a

Browse files
authored
Merge pull request #19877 from mozilla/FXA-12742
task(many): Upgrade Sentry and reduce filtering
2 parents 99b86c1 + fbcfb4b commit 810c57a

69 files changed

Lines changed: 974 additions & 3787 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libs/payments/webhooks/src/lib/stripe-webhooks.service.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ import {
5252
NimbusManager,
5353
} from '@fxa/payments/experiments';
5454

55-
jest.mock('@sentry/node', () => ({
56-
captureException: jest.fn(),
57-
}));
55+
jest.mock('@sentry/node', () => {
56+
const actual = jest.requireActual('@sentry/node');
57+
return {
58+
...actual,
59+
captureException: jest.fn(),
60+
};
61+
});
5862

5963
describe('StripeWebhookService', () => {
6064
let stripeEventManager: StripeEventManager;

libs/shared/sentry-browser/src/lib/browser.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import * as Sentry from '@sentry/browser';
66
import { enableSentry, SentryConfigOpts } from '@fxa/shared/sentry-utils';
77
import { captureException, initSentry } from './browser';
88

9+
jest.mock('@sentry/browser', () => {
10+
const actual = jest.requireActual('@sentry/browser');
11+
return {
12+
...actual,
13+
init: jest.fn(),
14+
captureException: jest.fn(),
15+
};
16+
});
17+
918
const config: SentryConfigOpts = {
1019
release: 'v0.0.0',
1120
sentry: {

libs/shared/sentry-nest/src/lib/nest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function initSentry(config: InitSentryOpts, log: Logger) {
2525

2626
const integrations = [
2727
Sentry.extraErrorDataIntegration({ depth: 5 }),
28+
Sentry.requestDataIntegration(),
2829

2930
// Custom Integrations
3031
...(config.integrations || []),

libs/shared/sentry-nest/src/lib/reporting.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ export function reportRequestException(
118118
Sentry.withScope((scope: Sentry.Scope) => {
119119
scope.addEventProcessor((event) => {
120120
if (request) {
121-
event.request = Sentry.extractRequestData(request);
121+
// As of sentry v9, this should automatically happen by adding, Sentry.requestDataIntegration()
122+
// Leaving note here for historical context.
123+
// event.request = Sentry.extractRequestData(request);
122124
event.level = 'error';
123125
return event;
124126
}

libs/shared/sentry-next/src/lib/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function initSentryForNextjsServer(config: InitSentryOpts, log: Logger) {
2828
const integrations = [
2929
// Default
3030
Sentry.extraErrorDataIntegration({ depth: 5 }),
31+
Sentry.requestDataIntegration(),
3132

3233
// Custom Integrations
3334
...(config.integrations || []),

libs/shared/sentry-node/src/lib/node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function initSentry(config: InitSentryOpts, log: Logger) {
2525

2626
const integrations = [
2727
Sentry.extraErrorDataIntegration({ depth: 5 }),
28+
Sentry.requestDataIntegration(),
2829

2930
// Custom Integrations
3031
...(config.integrations || []),

libs/shared/sentry-utils/src/lib/before-send.browser.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ describe('before send', () => {
7878
const url = 'https://accounts.firefox.com/complete_reset_password';
7979
const badQuery =
8080
'?token=foo&code=bar&email=some%40restmail.net&service=sync';
81-
const goodQuery = '?token=VALUE&code=VALUE&email=VALUE&service=sync';
81+
// We now allow these parameters to pass through. Leaving test for historical context.
82+
const goodQuery =
83+
'?token=foo&code=bar&email=some%40restmail.net&service=sync';
8284
const badData = {
8385
type: undefined,
8486
request: {
@@ -100,7 +102,9 @@ describe('before send', () => {
100102
const url = 'https://accounts.firefox.com/complete_reset_password';
101103
const badQuery =
102104
'?token=foo&code=bar&email=some%40restmail.net&service=sync';
103-
const goodQuery = '?token=VALUE&code=VALUE&email=VALUE&service=sync';
105+
// We now allow these parameters to pass through. Leaving test for historical context.
106+
const goodQuery =
107+
'?token=foo&code=bar&email=some%40restmail.net&service=sync';
104108
const badData = {
105109
type: undefined,
106110
request: {
@@ -129,8 +133,9 @@ describe('before send', () => {
129133
const badCulprit = 'https://accounts.firefox.com/scripts/57f6d4e4.main.js';
130134
const badAbsPath =
131135
'https://accounts.firefox.com/complete_reset_password?token=foo&code=bar&[email protected]&service=sync&resume=barbar';
136+
// We now allow these parameters to pass through. Leaving test for historical context.
132137
const goodAbsPath =
133-
'https://accounts.firefox.com/complete_reset_password?token=VALUE&code=VALUE&email=VALUE&service=sync&resume=VALUE';
138+
'https://accounts.firefox.com/complete_reset_password?token=foo&code=bar&email=[email protected]&service=sync&resume=barbar';
134139
const data = {
135140
type: undefined,
136141
culprit: badCulprit,

libs/shared/sentry-utils/src/lib/before-send.browser.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { ErrorEvent, EventHint, Exception } from '@sentry/core';
2-
import {
3-
SentryConfigOpts,
4-
tagFxaName,
5-
cleanUpQueryParam,
6-
} from '@fxa/shared/sentry-utils';
1+
import { ErrorEvent, EventHint } from '@sentry/core';
2+
import { SentryConfigOpts, tagFxaName } from '@fxa/shared/sentry-utils';
73

84
// Internal flag to keep track of whether or not sentry is initialized
95
let sentryEnabled = false;
@@ -36,10 +32,6 @@ export function beforeSendBrowser(
3632
}
3733

3834
if (event.request) {
39-
if (event.request.url) {
40-
event.request.url = cleanUpQueryParam(event.request.url);
41-
}
42-
4335
if (event.tags) {
4436
// if this is a known errno, then use grouping with fingerprints
4537
// Docs: https://docs.sentry.io/hosted/learn/rollups/#fallback-grouping
@@ -49,24 +41,6 @@ export function beforeSendBrowser(
4941
event.level = 'info';
5042
}
5143
}
52-
53-
if (event.exception?.values) {
54-
event.exception.values.forEach((value: Exception) => {
55-
if (value.stacktrace && value.stacktrace.frames) {
56-
value.stacktrace.frames.forEach((frame: { abs_path?: string }) => {
57-
if (frame.abs_path) {
58-
frame.abs_path = cleanUpQueryParam(frame.abs_path); // eslint-disable-line camelcase
59-
}
60-
});
61-
}
62-
});
63-
}
64-
65-
if (event.request.headers?.['Referer']) {
66-
event.request.headers['Referer'] = cleanUpQueryParam(
67-
event.request.headers['Referer']
68-
);
69-
}
7044
}
7145

7246
event = tagFxaName(event, opts.sentry?.clientName || opts.sentry?.serverName);

libs/shared/sentry-utils/src/lib/before-send.server.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import { beforeSendServer } from './before-send.server';
6-
import { filterSentryEvent } from './utils';
76

87
describe('beforeSendServer', () => {
98
const config = {
@@ -14,7 +13,7 @@ describe('beforeSendServer', () => {
1413
clientName: 'fxa-shared-testing',
1514
sampleRate: 0,
1615
},
17-
eventFilters: [filterSentryEvent],
16+
eventFilters: [],
1817
};
1918

2019
it('adjust event before send', () => {
@@ -28,6 +27,6 @@ describe('beforeSendServer', () => {
2827
const hint = {};
2928
const modified = beforeSendServer(config, data, hint);
3029
expect(modified?.tags?.['fxa.name']).toEqual('unknown');
31-
expect(modified?.extra?.['uid']).toEqual('[Filtered]');
30+
expect(modified?.extra?.['uid']).toEqual('123');
3231
});
3332
});

0 commit comments

Comments
 (0)