Merge pull request #16773 from mozilla/event-broker-report-sentry-errors

This commit is contained in:
Dan Schomburg 2024-04-24 07:35:05 -07:00 коммит произвёл GitHub
Родитель ad815fc7e7 045c9cf87c
Коммит ca6c2b3f07
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
9 изменённых файлов: 43 добавлений и 3 удалений

Просмотреть файл

@ -5,6 +5,7 @@ import { Provider } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ScheduleModule } from '@nestjs/schedule';
import { Test, TestingModule } from '@nestjs/testing';
import Sentry from '@sentry/node';
import { MozLoggerService } from 'fxa-shared/nestjs/logger/logger.service';
import { ClientCapabilityService } from './client-capability.service';
@ -17,6 +18,10 @@ const baseClients = [
},
];
jest.mock('@sentry/node', () => ({
captureException: jest.fn(),
}));
describe('ClientCapabilityService', () => {
let service: ClientCapabilityService;
let log: any;
@ -106,6 +111,7 @@ describe('ClientCapabilityService', () => {
(service as any).axiosInstance = { get: mockUpdate };
await service.updateCapabilities();
expect((service as any).log.error).toBeCalledTimes(1);
expect(Sentry.captureException).toBeCalledTimes(1);
});
});
});

Просмотреть файл

@ -8,6 +8,8 @@ import {
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { SchedulerRegistry } from '@nestjs/schedule';
import Sentry from '@sentry/node';
import axios, { AxiosInstance, AxiosResponse } from 'axios';
import { ExtendedError } from 'fxa-shared/nestjs/error';
import { MozLoggerService } from 'fxa-shared/nestjs/logger/logger.service';
@ -58,6 +60,7 @@ export class ClientCapabilityService
: undefined,
message: 'Error fetching client capabilities.',
});
Sentry.captureException(err);
return;
}
this.log.debug('updateCapabilities', { clientCapabilities: result.data });

Просмотреть файл

@ -7,6 +7,11 @@ import { MozLoggerService } from 'fxa-shared/nestjs/logger/logger.service';
import { FirestoreService } from '../firestore/firestore.service';
import { ClientWebhooksService } from './client-webhooks.service';
import Sentry from '@sentry/node';
jest.mock('@sentry/node', () => ({
captureException: jest.fn(),
}));
describe('ClientWebhooksService', () => {
let service: ClientWebhooksService;
@ -116,6 +121,7 @@ describe('ClientWebhooksService', () => {
triggerError(new Error('oops'));
expect(mockExit).toBeCalledTimes(1);
expect(log.error).toBeCalledTimes(1);
expect(Sentry.captureException).toBeCalledTimes(1);
});
});
});

Просмотреть файл

@ -6,6 +6,7 @@ import {
OnApplicationBootstrap,
OnApplicationShutdown,
} from '@nestjs/common';
import Sentry from '@sentry/node';
import { MozLoggerService } from 'fxa-shared/nestjs/logger/logger.service';
import { FirestoreService } from '../firestore/firestore.service';
@ -55,6 +56,7 @@ export class ClientWebhooksService
},
(err) => {
this.log.error('listenForClientIdWebhooks', { err });
Sentry.captureException(err);
process.exit(1);
}
);

Просмотреть файл

@ -4,6 +4,7 @@
import { Provider } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import Sentry from '@sentry/node';
import { MozLoggerService } from 'fxa-shared/nestjs/logger/logger.service';
import nock from 'nock';
@ -12,6 +13,10 @@ import { JwtsetService } from '../jwtset/jwtset.service';
import * as dto from '../queueworker/sqs.dto';
import { PubsubProxyController } from './pubsub-proxy.controller';
jest.mock('@sentry/node', () => ({
captureException: jest.fn(),
}));
const TEST_TOKEN =
'eyJhbGciOiJSUzI1NiIsImtpZCI6IjdkNjgwZDhjNzBkNDRlOTQ3MTMzY2JkNDk5ZWJjMWE2MWMzZDVhYmMiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwczovL2V4YW1wbGUuY29tIiwiYXpwIjoiMTEzNzc0MjY0NDYzMDM4MzIxOTY0IiwiZW1haWwiOiJnYWUtZ2NwQGFwcHNwb3QuZ3NlcnZpY2VhY2NvdW50LmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJleHAiOjE1NTAxODU5MzUsImlhdCI6MTU1MDE4MjMzNSwiaXNzIjoiaHR0cHM6Ly9hY2NvdW50cy5nb29nbGUuY29tIiwic3ViIjoiMTEzNzc0MjY0NDYzMDM4MzIxOTY0In0.QVjyqpmadTyDZmlX2u3jWd1kJ68YkdwsRZDo-QxSPbxjug4ucLBwAs2QePrcgZ6hhkvdc4UHY4YF3fz9g7XHULNVIzX5xh02qXEH8dK6PgGndIWcZQzjSYfgO-q-R2oo2hNM5HBBsQN4ARtGK_acG-NGGWM3CQfahbEjZPAJe_B8M7HfIu_G5jOLZCw2EUcGo8BvEwGcLWB2WqEgRM0-xt5-UPzoa3-FpSPG7DHk7z9zRUeq6eB__ldb-2o4RciJmjVwHgnYqn3VvlX9oVKEgXpNFhKuYA-mWh5o7BCwhujSMmFoBOh6mbIXFcyf5UiVqKjpqEbqPGo_AvKvIQ9VTQ';
const TEST_CLIENT_ID = 'abc1234';
@ -222,7 +227,7 @@ describe('PubsubProxy Controller', () => {
it('logs an error on invalid message payloads', async () => {
const message = Buffer.from('invalid payload').toString('base64');
expect.assertions(2);
expect.assertions(3);
let err: { getStatus: () => number } | undefined = undefined;
try {
await controller.proxy(
@ -238,6 +243,7 @@ describe('PubsubProxy Controller', () => {
expect(err?.getStatus()).toBe(400);
expect(logger.error).toBeCalledTimes(1);
expect(Sentry.captureException).toBeCalledTimes(1);
});
it('proxies an error code back', async () => {

Просмотреть файл

@ -16,6 +16,7 @@ import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import { Request } from 'express';
import { MozLoggerService } from 'fxa-shared/nestjs/logger/logger.service';
import { StatsD } from 'hot-shots';
import Sentry from '@sentry/node';
import { ExtendedError } from 'fxa-shared/nestjs/error';
import { GoogleJwtAuthGuard } from '../auth/google-jwt-auth.guard';
@ -98,6 +99,7 @@ export class PubsubProxyController {
message: 'Failure to load message payload',
err,
});
Sentry.captureException(err);
throw new BadRequestException('Invalid message');
}
}
@ -147,6 +149,7 @@ export class PubsubProxyController {
return err.response;
} else {
this.log.error('proxyDeliverError', { err });
Sentry.captureException(err);
throw ExtendedError.withCause('Proxy delivery error', err);
}
}
@ -204,7 +207,7 @@ export class PubsubProxyController {
appleEmail: message.appleEmail,
transferSub: message.transferSub,
success: message.success,
err: message.error
err: message.error,
});
}
default:

Просмотреть файл

@ -5,12 +5,18 @@ import { Provider } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import { MozLoggerService } from 'fxa-shared/nestjs/logger/logger.service';
import Sentry from '@sentry/node';
import { ClientCapabilityService } from '../client-capability/client-capability.service';
import { FirestoreService } from '../firestore/firestore.service';
import { QueueworkerService } from './queueworker.service';
import { ClientWebhooksService } from '../client-webhooks/client-webhooks.service';
jest.mock('@sentry/node', () => ({
captureException: jest.fn(),
captureMessage: jest.fn(),
}));
const now = Date.now();
const baseMessage = {
@ -103,6 +109,8 @@ describe('QueueworkerService', () => {
};
beforeEach(async () => {
jest.resetAllMocks();
firestore = {
storeLogin: jest.fn().mockResolvedValue({}),
deleteUser: jest.fn().mockResolvedValue({}),
@ -321,6 +329,7 @@ describe('QueueworkerService', () => {
await (service as any).handleMessage(msg);
expect(logger.error).toBeCalledTimes(1);
expect(logger.error.mock.calls[0][0]).toBe('from.sqsMessage');
expect(Sentry.captureException).toBeCalledTimes(1);
}
for (const [key, value] of Object.entries(invalidMessages)) {

Просмотреть файл

@ -18,6 +18,7 @@ import { ConfigService } from '@nestjs/config';
import { MozLoggerService } from 'fxa-shared/nestjs/logger/logger.service';
import { StatsD } from 'hot-shots';
import { Consumer } from 'sqs-consumer';
import Sentry from '@sentry/node';
import { ClientCapabilityService } from '../client-capability/client-capability.service';
import { ClientWebhooksService } from '../client-webhooks/client-webhooks.service';
@ -80,12 +81,15 @@ export class QueueworkerService
queueUrl: this.queueName,
sqs: this.sqs,
});
this.app.on('error', (err) => {
this.log.error('consumerError', { err });
Sentry.captureException(err);
});
this.app.on('processing_error', (err) => {
this.log.error('processingError', { err });
Sentry.captureException(err);
});
}
@ -107,6 +111,7 @@ export class QueueworkerService
// Production queue names must have the region in them.
const region = extractRegionFromUrl(this.queueName);
if (!region) {
Sentry.captureMessage('Cant find region in service url');
this.log.error('invalidServiceUrl', {
message: 'Cant find region in service url',
serviceNotificationQueueUrl: this.queueName,

Просмотреть файл

@ -66,11 +66,11 @@ export const ServiceNotification = {
return validMessage;
}
} catch (err) {
Sentry.captureException(err);
logger.error('from.sqsMessage', {
message: 'Invalid message',
err,
});
Sentry.captureException(err);
}
return;
},