Skip to content

Commit d3be5f3

Browse files
committed
deps(sentry): upgrade Sentry to version 8
Because: - Sentry 8 is the latest version This commit: - deletes some integration code since Sentry does it automatically - updates code to use the Sentry 8 API - updates a few proxyquire calls because they were cause module not found errors in CI
1 parent 3da291f commit d3be5f3

File tree

33 files changed

+432
-591
lines changed

33 files changed

+432
-591
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ export const _Sentry = {
4949
* Modified error object data
5050
* @private
5151
*/
52-
function beforeSend(opts: SentryConfigOpts, event: Sentry.Event, hint?: any) {
52+
function beforeSend(
53+
opts: SentryConfigOpts,
54+
event: Sentry.ErrorEvent,
55+
hint?: Sentry.EventHint
56+
) {
5357
if (sentryEnabled === false) {
5458
return null;
5559
}
@@ -166,12 +170,7 @@ function configure(config: SentryConfigOpts, log?: Logger) {
166170
try {
167171
Sentry.init({
168172
...opts,
169-
integrations: [
170-
Sentry.browserTracingIntegration({
171-
enableInp: true,
172-
}),
173-
],
174-
beforeSend: function (event: Sentry.Event, hint?: any) {
173+
beforeSend: function (event: Sentry.ErrorEvent, hint: Sentry.EventHint) {
175174
return beforeSend(opts, event, hint);
176175
},
177176
});

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
NestInterceptor,
1313
} from '@nestjs/common';
1414
import * as Sentry from '@sentry/node';
15-
import { Transaction } from '@sentry/types';
1615

1716
import { ignoreError, processException } from '../reporting';
1817

@@ -22,11 +21,13 @@ export class SentryInterceptor implements NestInterceptor {
2221
// If there is http context request start a transaction for it. Note that this will not
2322
// pick up graphql queries
2423
const req = context.switchToHttp().getRequest();
25-
let transaction: Transaction;
24+
let transaction: Sentry.Span;
25+
2626
if (req) {
27-
transaction = Sentry.startTransaction({
27+
transaction = Sentry.startInactiveSpan({
2828
op: 'nestjs.http',
2929
name: `${req.method} ${req.path}`,
30+
forceTransaction: true,
3031
});
3132
}
3233

@@ -42,7 +43,7 @@ export class SentryInterceptor implements NestInterceptor {
4243
},
4344
}),
4445
finalize(() => {
45-
transaction?.finish();
46+
transaction?.end();
4647
})
4748
);
4849
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
} from '@apollo/server';
2323
import { Plugin } from '@nestjs/apollo';
2424
import * as Sentry from '@sentry/node';
25-
import { Transaction } from '@sentry/types';
2625

2726
import {
2827
ExtraContext,
@@ -33,14 +32,15 @@ import { Inject } from '@nestjs/common';
3332
import { MozLoggerService } from '@fxa/shared/mozlog';
3433

3534
interface Context extends BaseContext {
36-
transaction: Transaction;
35+
transaction: Sentry.Span;
3736
request: Request;
3837
}
3938

4039
export async function createContext(ctx: any): Promise<Context> {
41-
const transaction = Sentry.startTransaction({
40+
const transaction = Sentry.startInactiveSpan({
4241
op: 'gql',
4342
name: 'GraphQLTransaction',
43+
forceTransaction: true,
4444
});
4545
return { request: ctx.req, transaction };
4646
}
@@ -57,7 +57,7 @@ export class SentryPlugin implements ApolloServerPlugin<Context> {
5757

5858
if (request.operationName != null) {
5959
try {
60-
contextValue.transaction.setName(request.operationName);
60+
contextValue.transaction.updateName(request.operationName);
6161
} catch (err) {
6262
log.error('sentry-plugin', err);
6363
}
@@ -66,7 +66,7 @@ export class SentryPlugin implements ApolloServerPlugin<Context> {
6666
return {
6767
async willSendResponse({ contextValue }) {
6868
try {
69-
contextValue.transaction.finish();
69+
contextValue.transaction.end();
7070
} catch (err) {
7171
log.error('sentry-plugin', err);
7272
}
@@ -75,18 +75,19 @@ export class SentryPlugin implements ApolloServerPlugin<Context> {
7575
async executionDidStart() {
7676
return {
7777
willResolveField({ contextValue, info }) {
78-
let span: any;
78+
let span: Sentry.Span;
7979
try {
80-
span = contextValue.transaction.startChild({
80+
span = Sentry.startInactiveSpan({
8181
op: 'resolver',
82-
description: `${info.parentType.name}.${info.fieldName}`,
82+
name: `${info.parentType.name}.${info.fieldName}`,
83+
scope: contextValue.transaction,
8384
});
8485
} catch (err) {
8586
log.error('sentry-plugin', err);
8687
}
8788

8889
return () => {
89-
span?.finish();
90+
span?.end();
9091
};
9192
},
9293
};

libs/shared/sentry/src/lib/next/client.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ export function initSentryForNextjsClient(
3939
try {
4040
Sentry.init({
4141
...opts,
42-
integrations: [
43-
Sentry.browserTracingIntegration({
44-
enableInp: true,
45-
}),
46-
],
4742
beforeSend: function (event: Sentry.ErrorEvent) {
4843
return beforeSend(sentryEnabled, opts, event);
4944
},

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import * as Sentry from '@sentry/node';
66
import { ErrorEvent } from '@sentry/types';
7-
import { ExtraErrorData } from '@sentry/integrations';
7+
import { extraErrorDataIntegration } from '@sentry/node';
88
import { SentryConfigOpts } from './models/SentryConfigOpts';
99
import { buildSentryConfig } from './config-builder';
1010
import { tagFxaName } from './reporting';
@@ -39,8 +39,7 @@ export function initSentry(config: InitSentryOpts, log: Logger) {
3939
};
4040

4141
const integrations = [
42-
// Default
43-
new ExtraErrorData({ depth: 5 }),
42+
extraErrorDataIntegration({ depth: 5 }),
4443

4544
// Custom Integrations
4645
...(config.integrations || []),
@@ -49,7 +48,6 @@ export function initSentry(config: InitSentryOpts, log: Logger) {
4948
try {
5049
Sentry.init({
5150
// Defaults Options
52-
instrumenter: 'otel',
5351
normalizeDepth: 6,
5452
maxValueLength: 500,
5553

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ export function reportRequestException(
167167
}
168168

169169
Sentry.withScope((scope: Sentry.Scope) => {
170-
scope.addEventProcessor((event: Sentry.Event) => {
170+
scope.addEventProcessor((event) => {
171171
if (request) {
172-
const sentryEvent = Sentry.Handlers.parseRequest(event, request);
173-
sentryEvent.level = 'error';
174-
return sentryEvent;
172+
event.request = Sentry.extractRequestData(request);
173+
event.level = 'error';
174+
return event;
175175
}
176176
return null;
177177
});

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@
7676
"@paypal/react-paypal-js": "^8.7.0",
7777
"@radix-ui/react-form": "^0.0.3",
7878
"@radix-ui/react-tooltip": "^1.1.2",
79-
"@sentry/browser": "^7.113.0",
80-
"@sentry/integrations": "^7.113.0",
81-
"@sentry/nextjs": "^8",
82-
"@sentry/node": "^7.113.0",
83-
"@sentry/opentelemetry-node": "^7.113.0",
79+
"@sentry/browser": "^8.28.0",
80+
"@sentry/nextjs": "^8.28.0",
81+
"@sentry/node": "^8.28.0",
82+
"@sentry/opentelemetry": "^8.28.0",
8483
"@swc/helpers": "0.5.11",
8584
"@type-cacheable/core": "^14.1.0",
8685
"@type-cacheable/ioredis-adapter": "^10.0.4",

packages/browserid-verifier/lib/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if (sentryConfig.dsn) {
4747
return event;
4848
},
4949
});
50-
app.use(Sentry.Handlers.requestHandler());
50+
Sentry.setupExpressErrorHandler(app);
5151
}
5252

5353
var verifier = new CCVerifier({

packages/fxa-admin-panel/server/lib/server.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ logger.info('version', { version: version });
3030

3131
// Initialize Sentry
3232
const sentryConfig = config.get('sentry');
33-
if (sentryConfig.dsn) {
34-
app.use(Sentry.Handlers.requestHandler());
35-
}
3633

3734
app.use(
3835
helmet.frameguard({
@@ -145,7 +142,7 @@ if (proxyUrl) {
145142

146143
// Send errors to sentry.
147144
if (sentryConfig.dsn) {
148-
app.use(Sentry.Handlers.errorHandler());
145+
Sentry.setupExpressErrorHandler(app);
149146
}
150147

151148
export default app;

packages/fxa-auth-server/lib/monitoring.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ initMonitoring({
2121
...config.getProperties(),
2222
release: version,
2323
eventFilters: [filterSentryEvent],
24-
integrations: [new Sentry.Integrations.LinkedErrors({ key: 'jse_cause' })],
24+
integrations: [Sentry.linkedErrorsIntegration({ key: 'jse_cause' })],
2525
},
2626
});
2727

packages/fxa-auth-server/lib/sentry.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ function reportSentryError(err, request) {
3434

3535
Sentry.withScope((scope) => {
3636
if (request) {
37-
scope.addEventProcessor((_sentryEvent) => {
38-
const sentryEvent = Sentry.Handlers.parseRequest(
39-
_sentryEvent,
40-
request.raw.req
41-
);
37+
scope.addEventProcessor((sentryEvent) => {
38+
sentryEvent.request = Sentry.extractRequestData(request.raw.req);
4239
sentryEvent.level = 'error';
4340
return sentryEvent;
4441
});
@@ -106,9 +103,7 @@ function reportSentryError(err, request) {
106103

107104
async function configureSentry(server, config, processName = 'key_server') {
108105
if (config.sentry.dsn) {
109-
Sentry.configureScope((scope) => {
110-
scope.setTag('process', processName);
111-
});
106+
Sentry.getCurrentScope().setTag('process', processName);
112107

113108
if (!server) {
114109
return;
@@ -120,6 +115,7 @@ async function configureSentry(server, config, processName = 'key_server') {
120115
method(request, h) {
121116
request.sentryScope = new Sentry.Scope();
122117

118+
/**
123119
// Make a transaction per request so we can get performance monitoring. There are
124120
// some limitations to this approach, and distributed tracing will be off due to
125121
// hapi's architecture.
@@ -128,23 +124,17 @@ async function configureSentry(server, config, processName = 'key_server') {
128124
// looks like there might be some other solutions that are more complex, but would work
129125
// with hapi and distributed tracing.
130126
//
131-
const transaction = Sentry.startTransaction(
132-
{
133-
op: 'auth-server',
134-
name: `${request.method.toUpperCase()} ${request.path}`,
135-
},
136-
{
137-
request: Sentry.Handlers.extractRequestData(request.raw.req),
138-
}
139-
);
140-
141-
Sentry.configureScope((scope) => {
142-
scope.setSpan(transaction);
127+
const transaction = Sentry.startInactiveSpan({
128+
op: 'auth-server',
129+
name: `${request.method.toUpperCase()} ${request.path}`,
130+
forceTransaction: true,
131+
request: Sentry.extractRequestData(request.raw.req),
143132
});
144133
145134
request.app.sentry = {
146135
transaction,
147136
};
137+
//*/
148138

149139
return h.continue;
150140
},

packages/fxa-auth-server/test/oauth/routes/jwks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
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/. */
44

5+
const path = require('path');
56
const { assert } = require('chai');
67
const proxyquire = require('proxyquire');
78
const mocks = require('../../lib/mocks');
89
const keys = require('../../../lib/oauth/keys');
910

10-
const routeModulePath = '../../../lib/routes/oauth/jwks';
11+
const routeModulePath = path.join(__dirname, '../../../lib/routes/oauth/jwks');
1112
var dependencies = mocks.require(
1213
[{ path: '../../oauth/keys' }],
1314
routeModulePath,

packages/fxa-auth-server/test/oauth/routes/token.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const { assert } = require('chai');
66
const buf = require('buf').hex;
77
const hex = require('buf').to.hex;
8+
const path = require('path');
89
const proxyquire = require('proxyquire');
910
const sinon = require('sinon');
1011

@@ -23,7 +24,8 @@ const CODE_WITHOUT_KEYS = 'f0f0f0';
2324
const mockDb = { touchSessionToken: sinon.stub() };
2425
const mockStatsD = { increment: sinon.stub() };
2526
const mockGlean = { oauth: { tokenCreated: sinon.stub() } };
26-
const tokenRoutes = proxyquire('../../../lib/routes/oauth/token', {
27+
const tokenRoutePath = path.join(__dirname, '../../../lib/routes/oauth/token');
28+
const tokenRoutes = proxyquire(tokenRoutePath, {
2729
'../../oauth/assertion': async () => true,
2830
'../../oauth/client': {
2931
authenticateClient: (_, params) => ({

packages/fxa-auth-server/test/oauth/routes/verify.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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/. */
44

5+
const path = require('path');
56
const { assert } = require('chai');
67
const proxyquire = require('proxyquire');
78
const sinon = require('sinon');
@@ -50,7 +51,7 @@ describe('/verify POST', () => {
5051
};
5152

5253
route = proxyquire(
53-
'../../../lib/routes/oauth/verify',
54+
path.join(__dirname, '../../../lib/routes/oauth/verify'),
5455
dependencies
5556
)({ log: mocks.log, glean: mocks.glean });
5657
});

packages/fxa-content-server/app/scripts/lib/sentry.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ function SentryMetrics(config) {
134134
const opts = buildSentryConfig(config, this._logger);
135135
Sentry.init({
136136
...opts,
137-
instrumenter: 'otel',
138-
integrations: [
139-
Sentry.browserTracingIntegration({
140-
enableInp: true,
141-
}),
142-
],
143137
beforeSend(event) {
144138
event = tagFxaName(event, opts.clientName);
145139
event = beforeSend(event);

0 commit comments

Comments
 (0)