Skip to content

Commit

Permalink
task(many): Upgrade sentry and enable tracing
Browse files Browse the repository at this point in the history
Because:
- We want to enable performance monitoring
- We want to upgrade sentry

This Commit:
- Upgrades sentry to the latest version
- Enables tracing by setting the tracesSampleRate to 1 by default.
- Tracing can be altered / disabled by setting SENTRY_TRACES_SAMPLE_RATE to a value between 0 and 1.
  • Loading branch information
dschom committed Sep 13, 2023
1 parent 6e062cc commit 850acfa
Show file tree
Hide file tree
Showing 57 changed files with 381 additions and 599 deletions.
8 changes: 7 additions & 1 deletion packages/browserid-verifier/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function loadConf() {
env: 'SENTRY_ENV',
},
sampleRate: {
doc: 'Rate at which sentry traces are captured.',
doc: 'Rate at which sentry errors are captured.',
default: 1.0,
format: 'Number',
env: 'SENTRY_SAMPLE_RATE',
Expand All @@ -108,6 +108,12 @@ function loadConf() {
format: 'String',
env: 'SENTRY_SERVER_NAME',
},
tracesSampleRate: {
doc: 'Rate at which sentry traces are captured',
default: 1.0,
format: 'Number',
env: 'SENTRY_TRACES_SAMPLE_RATE',
},
},
testServiceFailure: {
doc: '(testing only) trigger a service failure in the verifier',
Expand Down
3 changes: 1 addition & 2 deletions packages/browserid-verifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"bugs": "https://github.com/mozilla/fxa/issues/",
"main": "lib/server.js",
"dependencies": {
"@sentry/integrations": "6.19.7",
"@sentry/node": "6.19.7",
"@sentry/node": "^7.66.0",
"async": "3.2.4",
"body-parser": "^1.20.1",
"browserid-local-verify": "0.5.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/fxa-admin-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"dependencies": {
"@apollo/client": "^3.4.5",
"@sentry/node": "^7.3.1",
"@sentry/browser": "^7.66.0",
"@sentry/node": "^7.66.0",
"body-parser": "^1.20.1",
"convict": "^6.2.4",
"convict-format-with-moment": "^6.2.0",
Expand Down
8 changes: 7 additions & 1 deletion packages/fxa-admin-panel/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const conf = convict({
env: 'SENTRY_ENV',
},
sampleRate: {
doc: 'Rate at which sentry traces are captured.',
doc: 'Rate at which sentry errors are captured.',
default: 1.0,
format: 'Number',
env: 'SENTRY_SAMPLE_RATE',
Expand All @@ -88,6 +88,12 @@ const conf = convict({
format: 'String',
env: 'SENTRY_CLIENT_NAME',
},
tracesSampleRate: {
doc: 'Rate at which sentry traces are captured',
default: 1.0,
format: 'Number',
env: 'SENTRY_TRACES_SAMPLE_RATE',
},
},
listen: {
host: {
Expand Down
1 change: 1 addition & 0 deletions packages/fxa-admin-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"@golevelup/ts-jest": "^0.3.2",
"@google-cloud/firestore": "^6.6.0",
"@sentry/node": "^7.66.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"convict": "^6.2.4",
Expand Down
8 changes: 7 additions & 1 deletion packages/fxa-admin-server/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const conf = convict({
env: 'SENTRY_ENV',
},
sampleRate: {
doc: 'Rate at which sentry traces are captured.',
doc: 'Rate at which sentry errors are captured.',
default: 1.0,
format: 'Number',
env: 'SENTRY_SAMPLE_RATE',
Expand All @@ -112,6 +112,12 @@ const conf = convict({
format: 'String',
env: 'SENTRY_SERVER_NAME',
},
tracesSampleRate: {
doc: 'Rate at which sentry traces are captured',
default: 1.0,
format: 'Number',
env: 'SENTRY_TRACES_SAMPLE_RATE',
},
},
subscriptions: {
enabled: {
Expand Down
8 changes: 7 additions & 1 deletion packages/fxa-auth-server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ const convictConf = convict({
env: 'SENTRY_ENV',
},
sampleRate: {
doc: 'Rate at which sentry traces are captured.',
doc: 'Rate at which sentry errors are captured.',
default: 1.0,
format: 'Number',
env: 'SENTRY_SAMPLE_RATE',
Expand All @@ -1653,6 +1653,12 @@ const convictConf = convict({
format: 'String',
env: 'SENTRY_SERVER_NAME',
},
tracesSampleRate: {
doc: 'Rate at which sentry traces are captured',
default: 1.0,
format: 'Number',
env: 'SENTRY_TRACES_SAMPLE_RATE',
},
},
totp: {
serviceName: {
Expand Down
3 changes: 2 additions & 1 deletion packages/fxa-auth-server/lib/google-maps-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Status,
} from '@googlemaps/google-maps-services-js';
import * as Sentry from '@sentry/node';
import { SeverityLevel } from '@sentry/types';
import countries from 'i18n-iso-countries';
import { Container } from 'typedi';

Expand Down Expand Up @@ -49,7 +50,7 @@ export class GoogleMapsService {
scope.setContext('googleMapsService', {
address,
});
Sentry.captureMessage(error.message, Sentry.Severity.Error);
Sentry.captureMessage(error.message, 'error' as SeverityLevel);
});
throw error;
}
Expand Down
5 changes: 1 addition & 4 deletions packages/fxa-auth-server/lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,7 @@ Lug.prototype.amplitudeEvent = function (data) {
flow_id: data.user_properties.flow_id,
error: err.message,
});
Sentry.captureMessage(
'Amplitude event failed validation',
Sentry.Severity.Error
);
Sentry.captureMessage('Amplitude event failed validation', 'error');
});
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/fxa-auth-server/lib/payments/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { Firestore } from '@google-cloud/firestore';
import * as Sentry from '@sentry/node';
import { SeverityLevel } from '@sentry/types';
import {
Cacheable,
CacheClearStrategy,
Expand Down Expand Up @@ -713,7 +714,7 @@ export class StripeHelper extends StripeHelperBase {
});
Sentry.captureMessage(
`Invoice Preview Error: Prorated Invoice Preview`,
Sentry.Severity.Error
'error' as SeverityLevel
);
});
this.log.error('subscriptions.previewInvoice.proratedInvoice', error);
Expand Down Expand Up @@ -914,7 +915,7 @@ export class StripeHelper extends StripeHelperBase {
});
Sentry.captureMessage(
'Coupon duration does not apply for entire plan interval',
Sentry.Severity.Error
'error' as SeverityLevel
);
});
return false;
Expand Down Expand Up @@ -2174,7 +2175,7 @@ export class StripeHelper extends StripeHelperBase {
});
Sentry.captureMessage(
'Payment charges not found in subscription payment intent on subscription creation.',
Sentry.Severity.Warning
'warning' as SeverityLevel
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { ServerRoute } from '@hapi/hapi';
import * as Sentry from '@sentry/node';
import { SeverityLevel } from '@sentry/types';
import { Account } from 'fxa-shared/db/models/auth';
import { ACTIVE_SUBSCRIPTION_STATUSES } from 'fxa-shared/subscriptions/stripe';
import isA from 'joi';
Expand Down Expand Up @@ -123,7 +124,7 @@ export class StripeWebhookHandler extends StripeHandler {
});
Sentry.captureMessage(
'Event being handled that is not using latest object from Stripe.',
Sentry.Severity.Info
'info' as SeverityLevel
);
});
}
Expand Down Expand Up @@ -207,7 +208,7 @@ export class StripeWebhookHandler extends StripeHandler {
});
Sentry.captureMessage(
'Unhandled Stripe event received.',
Sentry.Severity.Info
'info' as SeverityLevel
);
});
}
Expand Down Expand Up @@ -736,7 +737,7 @@ export class StripeWebhookHandler extends StripeHandler {

Sentry.withScope((scope) => {
scope.setContext('planUpdatedEvent', { plan });
Sentry.captureMessage(msg, Sentry.Severity.Error);
Sentry.captureMessage(msg, 'error' as SeverityLevel);
});

this.stripeHelper.updateAllPlans(updatedList);
Expand Down
8 changes: 6 additions & 2 deletions packages/fxa-auth-server/lib/routes/subscriptions/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { ServerRoute } from '@hapi/hapi';
import isA from 'joi';
import * as Sentry from '@sentry/node';
import { SeverityLevel } from '@sentry/types';
import { getAccountCustomerByUid } from 'fxa-shared/db/models/auth';
import {
AbbrevPlan,
Expand Down Expand Up @@ -475,7 +476,10 @@ export class StripeHandler {
error: err,
msg: err.message,
});
Sentry.captureMessage(`Invoice Preview Error.`, Sentry.Severity.Error);
Sentry.captureMessage(
`Invoice Preview Error.`,
'error' as SeverityLevel
);
});
this.log.error('subscriptions.previewInvoice', err);

Expand Down Expand Up @@ -775,7 +779,7 @@ export class StripeHandler {
});
Sentry.captureMessage(
`Cannot find a postal code or country for customer.`,
Sentry.Severity.Error
'error' as SeverityLevel
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/lib/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function reportSentryError(err, request) {
_sentryEvent,
request.raw.req
);
sentryEvent.level = Sentry.Severity.Error;
sentryEvent.level = 'error';
return sentryEvent;
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fxa-auth-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
"@hapi/hawk": "^8.0.0",
"@hapi/hoek": "^11.0.2",
"@mozilla/glean": "^2.0.0",
"@sentry/integrations": "^6.19.1",
"@sentry/node": "^6.19.1",
"@sentry/integrations": "^7.66.0",
"@sentry/node": "^7.66.0",
"@type-cacheable/core": "^11.0.0",
"@type-cacheable/ioredis-adapter": "^10.0.4",
"@types/convict": "5.2.2",
Expand Down
5 changes: 2 additions & 3 deletions packages/fxa-auth-server/test/local/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const { mockRequest, mockMetricsContext } = require('../mocks');
const mockAmplitudeConfig = { schemaValidation: true };

let sentryScope, mockSentry;
const Sentry = require('@sentry/node');

const validEvent = {
op: 'amplitudeEvent',
Expand Down Expand Up @@ -648,7 +647,7 @@ describe('log', () => {
assert.isTrue(
mockSentry.captureMessage.calledOnceWith(
'Amplitude event failed validation',
Sentry.Severity.Error
'error'
)
);

Expand Down Expand Up @@ -685,7 +684,7 @@ describe('log', () => {
assert.isTrue(
mockSentry.captureMessage.calledOnceWith(
'Amplitude event failed validation',
Sentry.Severity.Error
'error'
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ describe('DirectStripeRoutes', () => {
sinon.assert.calledOnceWithExactly(
Sentry.captureMessage,
`Cannot find a postal code or country for customer.`,
Sentry.Severity.Error
'error'
);
});

Expand Down
1 change: 1 addition & 0 deletions packages/fxa-content-server/app/scripts/lib/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function SentryMetrics(config) {
const opts = buildSentryConfig(config, this._logger);
Sentry.init({
...opts,
integrations: [new Sentry.BrowserTracing()],
beforeSend(event) {
event = tagFxaName(event, opts.clientName);
event = beforeSend(event);
Expand Down
5 changes: 2 additions & 3 deletions packages/fxa-content-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@mozilla/glean": "^2.0.0",
"@sentry/browser": "^6.19.7",
"@sentry/integrations": "^6.19.1",
"@sentry/node": "^6.19.1",
"@sentry/browser": "^7.66.0",
"@sentry/node": "^7.66.0",
"asmcrypto.js": "^0.22.0",
"babel-loader": "^9.1.2",
"backbone": "^1.4.1",
Expand Down
5 changes: 1 addition & 4 deletions packages/fxa-content-server/server/lib/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,10 +986,7 @@ function receiveEvent(event, request, data) {
flow_id: amplitudeEvent.user_properties.flow_id,
error: err.message,
});
Sentry.captureMessage(
'Amplitude event failed validation',
Sentry.Severity.Error
);
Sentry.captureMessage('Amplitude event failed validation', 'error');
});
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/fxa-content-server/server/lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,12 @@ const conf = (module.exports = convict({
env: 'SENTRY_SAMPLE_RATE',
format: Number,
},
tracesSampleRate: {
doc: 'Rate at which sentry traces are captured',
default: 1.0,
format: 'Number',
env: 'SENTRY_TRACES_SAMPLE_RATE',
},
},
sourceMapType: {
default: 'source-map',
Expand Down
2 changes: 1 addition & 1 deletion packages/fxa-content-server/server/lib/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function tryCaptureValidationError(err) {
Sentry.withScope((scope) => {
scope.setTag('error_type', 'validation_error');
scope.setContext('validationError', { validationError });
Sentry.captureMessage(message, Sentry.Severity.Error);
Sentry.captureMessage(message, 'error');
});

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const amplitude = proxyquire(path.resolve('server/lib/amplitude'), {
},
'@sentry/node': mockSentry,
});
const Sentry = require('@sentry/node');

registerSuite('amplitude json schema validation', {
beforeEach: function () {
Expand Down Expand Up @@ -132,7 +131,7 @@ registerSuite('amplitude json schema validation', {
assert.isTrue(
mockSentry.captureMessage.calledOnceWith(
'Amplitude event failed validation',
Sentry.Severity.Error
'error'
)
);
assert.isTrue(logger.info.calledOnce);
Expand Down
8 changes: 7 additions & 1 deletion packages/fxa-customs-server/lib/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ module.exports = function (fs, path, url, convict) {
env: 'SENTRY_ENV',
},
sampleRate: {
doc: 'Rate at which sentry traces are captured.',
doc: 'Rate at which sentry errors are captured.',
default: 1.0,
format: 'Number',
env: 'SENTRY_SAMPLE_RATE',
Expand All @@ -326,6 +326,12 @@ module.exports = function (fs, path, url, convict) {
format: 'String',
env: 'SENTRY_SERVER_NAME',
},
tracesSampleRate: {
doc: 'Rate at which sentry traces are captured',
default: 1.0,
format: 'Number',
env: 'SENTRY_TRACES_SAMPLE_RATE',
},
},
tracing: tracingConfig,
userDefinedRateLimitRules: {
Expand Down
Loading

0 comments on commit 850acfa

Please sign in to comment.