Skip to content

Commit 2878860

Browse files
authored
Merge pull request #20099 from mozilla/worktree-FXA-13051
task(many): Use SentryModule.forRoot() instead of useGlobalFilters
2 parents 891c9b0 + 1c9200c commit 2878860

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

packages/fxa-admin-server/src/app.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import {
1515
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
1616
import { Module } from '@nestjs/common';
1717
import { ConfigModule, ConfigService } from '@nestjs/config';
18-
import { APP_GUARD } from '@nestjs/core';
18+
import { APP_FILTER, APP_GUARD } from '@nestjs/core';
1919
import { GraphQLModule } from '@nestjs/graphql';
20+
import { SentryGlobalFilter, SentryModule } from '@sentry/nestjs/setup';
2021

2122
import { UserGroupGuard } from './auth/user-group-header.guard';
2223
import { BackendModule } from './backend/backend.module';
@@ -32,6 +33,7 @@ const version = getVersionInfo(__dirname);
3233

3334
@Module({
3435
imports: [
36+
SentryModule.forRoot(),
3537
ConfigModule.forRoot({
3638
load: [(): AppConfig => Config.getProperties()],
3739
isGlobal: true,
@@ -70,6 +72,10 @@ const version = getVersionInfo(__dirname);
7072
],
7173
controllers: [],
7274
providers: [
75+
{
76+
provide: APP_FILTER,
77+
useClass: SentryGlobalFilter,
78+
},
7379
MetricsFactory,
7480
{
7581
provide: APP_GUARD,

packages/fxa-admin-server/src/main.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
import './monitoring';
88

99
import { NestApplicationOptions } from '@nestjs/common';
10-
import { HttpAdapterHost, NestFactory } from '@nestjs/core';
10+
import { NestFactory } from '@nestjs/core';
1111
import { NestExpressApplication } from '@nestjs/platform-express';
1212
import { allowlistGqlQueries } from 'fxa-shared/nestjs/gql/gql-allowlist';
1313
import helmet from 'helmet';
1414
import cors from 'cors';
1515
import * as Sentry from '@sentry/nestjs';
16-
import { SentryGlobalFilter } from '@sentry/nestjs/setup';
1716

1817
import { AppModule } from './app.module';
1918
import Config, { AppConfig } from './config';
@@ -30,10 +29,6 @@ async function bootstrap() {
3029
nestConfig
3130
);
3231

33-
// Register Sentry exception filter with proper HttpAdapterHost
34-
const { httpAdapter } = app.get(HttpAdapterHost);
35-
app.useGlobalFilters(new SentryGlobalFilter(httpAdapter));
36-
3732
app.use(
3833
cors({
3934
origin: appConfig.cors.origin,

packages/fxa-event-broker/src/app.module.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
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
import { Module } from '@nestjs/common';
5+
import { APP_FILTER } from '@nestjs/core';
56
import { ConfigModule } from '@nestjs/config';
67
import { ScheduleModule } from '@nestjs/schedule';
8+
import { SentryGlobalFilter, SentryModule } from '@sentry/nestjs/setup';
79
import { HealthModule } from 'fxa-shared/nestjs/health/health.module';
810
import { LoggerModule } from 'fxa-shared/nestjs/logger/logger.module';
911
import { MetricsFactory } from 'fxa-shared/nestjs/metrics.service';
@@ -22,6 +24,7 @@ const version = getVersionInfo(__dirname);
2224

2325
@Module({
2426
imports: [
27+
SentryModule.forRoot(),
2528
AuthModule,
2629
ClientCapabilityModule,
2730
ClientWebhooksModule,
@@ -38,6 +41,12 @@ const version = getVersionInfo(__dirname);
3841
PubsubProxyModule,
3942
],
4043
controllers: [],
41-
providers: [MetricsFactory],
44+
providers: [
45+
{
46+
provide: APP_FILTER,
47+
useClass: SentryGlobalFilter,
48+
},
49+
MetricsFactory,
50+
],
4251
})
4352
export class AppModule {}

packages/fxa-event-broker/src/main.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
import './monitoring';
88

99
import * as Sentry from '@sentry/nestjs';
10-
import { SentryGlobalFilter } from '@sentry/nestjs/setup';
1110

1211
import { NestApplicationOptions } from '@nestjs/common';
1312
import { ConfigService } from '@nestjs/config';
14-
import { HttpAdapterHost, NestFactory } from '@nestjs/core';
13+
import { NestFactory } from '@nestjs/core';
1514
import mozLog from 'mozlog';
1615

1716
import { initTracing } from 'fxa-shared/tracing/node-tracing';
@@ -34,10 +33,6 @@ async function bootstrap() {
3433
const config: ConfigService<AppConfig> = app.get(ConfigService);
3534
const proxyConfig = config.get('proxy') as AppConfig['proxy'];
3635

37-
// Register Sentry exception filter with proper HttpAdapterHost
38-
const { httpAdapter } = app.get(HttpAdapterHost);
39-
app.useGlobalFilters(new SentryGlobalFilter(httpAdapter));
40-
4136
// Starts listening for shutdown hooks
4237
app.enableShutdownHooks();
4338

0 commit comments

Comments
 (0)