feat: add user to sentry (#3467)
* feat: wip add user to sentry * feat: wip interceptor * feat: wip add user to sentry * feat: add user into sentry errors * fix: hide stack trace in production * fix: properly log commands and handle exceptions * fix: filter command exceptions * feat: handle jobs errors
This commit is contained in:
@ -11,20 +11,45 @@ import { MessageQueueService } from 'src/integrations/message-queue/services/mes
|
||||
import { getJobClassName } from 'src/integrations/message-queue/utils/get-job-class-name.util';
|
||||
import { QueueWorkerModule } from 'src/queue-worker.module';
|
||||
|
||||
import { LoggerService } from './integrations/logger/logger.service';
|
||||
import { ExceptionHandlerService } from './integrations/exception-handler/exception-handler.service';
|
||||
import { filterException } from './filters/utils/global-exception-handler.util';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.createApplicationContext(QueueWorkerModule);
|
||||
let exceptionHandlerService: ExceptionHandlerService | undefined;
|
||||
let loggerService: LoggerService | undefined;
|
||||
|
||||
for (const queueName of Object.values(MessageQueue)) {
|
||||
const messageQueueService: MessageQueueService = app.get(queueName);
|
||||
|
||||
await messageQueueService.work(async (jobData: MessageQueueJobData) => {
|
||||
const jobClassName = getJobClassName(jobData.name);
|
||||
const job: MessageQueueJob<MessageQueueJobData> = app
|
||||
.select(JobsModule)
|
||||
.get(jobClassName, { strict: true });
|
||||
|
||||
await job.handle(jobData.data);
|
||||
try {
|
||||
const app = await NestFactory.createApplicationContext(QueueWorkerModule, {
|
||||
bufferLogs: true,
|
||||
});
|
||||
|
||||
loggerService = app.get(LoggerService);
|
||||
exceptionHandlerService = app.get(ExceptionHandlerService);
|
||||
|
||||
// Inject our logger
|
||||
app.useLogger(loggerService!);
|
||||
|
||||
for (const queueName of Object.values(MessageQueue)) {
|
||||
const messageQueueService: MessageQueueService = app.get(queueName);
|
||||
|
||||
await messageQueueService.work(async (jobData: MessageQueueJobData) => {
|
||||
const jobClassName = getJobClassName(jobData.name);
|
||||
const job: MessageQueueJob<MessageQueueJobData> = app
|
||||
.select(JobsModule)
|
||||
.get(jobClassName, { strict: true });
|
||||
|
||||
await job.handle(jobData.data);
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
loggerService?.error(err?.message, err?.name);
|
||||
|
||||
if (!filterException(err)) {
|
||||
exceptionHandlerService?.captureExceptions([err]);
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user