Skip to content

Commit 41053d9

Browse files
committed
fix(payments-next): Sentry reporting 'something went wrong' errors
Because: * Sentry should not be recording "something went wrong" errors This commit: * prevents generic errors from propagaiting to sentry * creates a separate sentry dsn for payment-next client errors Closes #FXA-11331
1 parent e1b04e9 commit 41053d9

11 files changed

Lines changed: 30 additions & 4 deletions

File tree

apps/payments/next/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ CSP__PAYPAL_API='https://www.sandbox.paypal.com'
9999

100100
# Sentry Config
101101
SENTRY__DSN=
102+
SENTRY__CLIENT_DSN=
102103
SENTRY__ENV=local
103104
SENTRY__SERVER_NAME=payments-next-server
104105
SENTRY__CLIENT_NAME=payments-next-client

apps/payments/next/config/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class SentryServerConfig {
3838
@IsString()
3939
dsn?: string;
4040

41+
@IsOptional()
42+
@IsString()
43+
clientDsn?: string;
44+
4145
@IsString()
4246
env!: string;
4347

apps/payments/next/sentry.server.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
88
import { initSentryForNextjsServer } from '@fxa/shared/sentry';
99
import { config } from './config';
10+
import { GENERIC_ERROR_MESSAGE } from '@fxa/shared/error/error';
1011

1112
initSentryForNextjsServer(
1213
{
1314
release: process.env.version,
14-
sentry: config.sentry,
15+
sentry: {
16+
...config.sentry,
17+
ignoreErrors: [new RegExp(`^${GENERIC_ERROR_MESSAGE}$`)],
18+
},
1519
},
1620
console
1721
);

libs/payments/ui/src/lib/client/providers/ConfigProvider.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export interface ConfigContextValues {
1111
paypalClientId: string;
1212
sentry: {
1313
dsn?: string;
14+
clientDsn?: string;
1415
env: string;
1516
clientName: string;
17+
ignoreErrors?: (string | RegExp)[];
1618
sampleRate: number;
1719
tracesSampleRate: number;
1820
};
@@ -23,8 +25,10 @@ export const ConfigContext = createContext<ConfigContextValues>({
2325
paypalClientId: '',
2426
sentry: {
2527
dsn: '',
28+
clientDsn: '',
2629
env: '',
2730
clientName: '',
31+
ignoreErrors: [],
2832
sampleRate: 1,
2933
tracesSampleRate: 1,
3034
},

libs/payments/ui/src/lib/client/providers/Providers.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@paypal/react-paypal-js';
1313
import { initSentryForNextjsClient } from '@fxa/shared/sentry/client';
1414
import { getClient as sentryGetClient } from '@sentry/nextjs';
15+
import { GENERIC_ERROR_MESSAGE } from '@fxa/shared/error/error';
1516

1617
interface ProvidersProps {
1718
config: ConfigContextValues;
@@ -38,7 +39,11 @@ export function Providers({
3839
if (!sentryGetClient()) {
3940
initSentryForNextjsClient({
4041
release: process.env.version,
41-
sentry: config.sentry,
42+
sentry: {
43+
...config.sentry,
44+
dsn: config.sentry.clientDsn,
45+
ignoreErrors: [new RegExp(`^${GENERIC_ERROR_MESSAGE}$`)],
46+
},
4247
});
4348
}
4449

libs/shared/error/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4-
export { BaseError, BaseMultiError, TypeError } from './lib/error';
4+
export { BaseError, BaseMultiError, TypeError, GENERIC_ERROR_MESSAGE } from './lib/error';
55
export { SanitizeExceptions } from './lib/sanitizeExceptionsDecorator';

libs/shared/error/src/lib/error.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ export class TypeError extends BaseError {
2525
super(...args);
2626
}
2727
}
28+
29+
export const GENERIC_ERROR_MESSAGE = 'Something went wrong';

libs/shared/error/src/lib/sanitizeExceptionsDecorator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Sentry from '@sentry/nextjs';
66
import { Inject } from '@nestjs/common';
77
import { ILogger } from '@fxa/shared/log';
88
import { LOGGER_PROVIDER } from '@fxa/shared/log';
9+
import { GENERIC_ERROR_MESSAGE } from './error';
910

1011
type Constructor<T> = new (...args: any[]) => T;
1112

@@ -97,5 +98,5 @@ function handleException(args: {
9798
},
9899
});
99100

100-
return new Error('Something went wrong');
101+
return new Error(GENERIC_ERROR_MESSAGE);
101102
}

libs/shared/sentry/src/lib/config-builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function buildSentryConfig(config: SentryConfigOpts, log: Logger) {
3636
serverName: config.sentry?.serverName,
3737
fxaName: config.sentry?.clientName || config.sentry?.serverName,
3838
tracesSampleRate: config.sentry?.tracesSampleRate,
39+
ignoreErrors: config.sentry?.ignoreErrors || [],
3940
};
4041

4142
return opts;

libs/shared/sentry/src/lib/models/SentryConfigOpts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export type SentryConfigOpts = {
2121
clientName?: string;
2222
/** The name of the active server. */
2323
serverName?: string;
24+
/** The string messages of errors that should be ignored. Strings and regex patterns are permitted.
25+
* When using strings, partial matches will be filtered out. If you need to filter by exact match, use regex patterns instead */
26+
ignoreErrors?: (string | RegExp)[];
2427

2528
/** When set to true, building a configuration will throw an error critical fields are missing. */
2629
strict?: boolean;

0 commit comments

Comments
 (0)