From b1c3b76d80a00371cf413f6eca69d9650a99aed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Magrin?= Date: Fri, 7 Jun 2024 11:21:24 +0200 Subject: [PATCH] fix: track job errors in Sentry --- .../src/database/typeorm/typeorm.module.ts | 4 ++++ .../engine/core-modules/core-engine.module.ts | 4 ---- .../message-queue/message-queue.explorer.ts | 21 +++++++++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/twenty-server/src/database/typeorm/typeorm.module.ts b/packages/twenty-server/src/database/typeorm/typeorm.module.ts index b24fe05bad944..bda843eae6f4a 100644 --- a/packages/twenty-server/src/database/typeorm/typeorm.module.ts +++ b/packages/twenty-server/src/database/typeorm/typeorm.module.ts @@ -3,6 +3,7 @@ import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm'; import { typeORMCoreModuleOptions } from 'src/database/typeorm/core/core.datasource'; import { EnvironmentModule } from 'src/engine/integrations/environment/environment.module'; +import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; import { TypeORMService } from './typeorm.service'; @@ -28,6 +29,9 @@ const coreTypeORMFactory = async (): Promise => ({ useFactory: coreTypeORMFactory, name: 'core', }), + TwentyORMModule.register({ + workspaceEntities: ['dist/src/**/*.workspace-entity{.ts,.js}'], + }), EnvironmentModule, ], providers: [TypeORMService], diff --git a/packages/twenty-server/src/engine/core-modules/core-engine.module.ts b/packages/twenty-server/src/engine/core-modules/core-engine.module.ts index a7acdc0f3f288..4fa8467538b91 100644 --- a/packages/twenty-server/src/engine/core-modules/core-engine.module.ts +++ b/packages/twenty-server/src/engine/core-modules/core-engine.module.ts @@ -10,7 +10,6 @@ import { TimelineMessagingModule } from 'src/engine/core-modules/messaging/timel import { TimelineCalendarEventModule } from 'src/engine/core-modules/calendar/timeline-calendar-event.module'; import { BillingModule } from 'src/engine/core-modules/billing/billing.module'; import { HealthModule } from 'src/engine/core-modules/health/health.module'; -import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; import { AnalyticsModule } from './analytics/analytics.module'; import { FileModule } from './file/file.module'; @@ -18,9 +17,6 @@ import { ClientConfigModule } from './client-config/client-config.module'; @Module({ imports: [ - TwentyORMModule.register({ - workspaceEntities: ['dist/src/**/*.workspace-entity{.ts,.js}'], - }), HealthModule, AnalyticsModule, AuthModule, diff --git a/packages/twenty-server/src/engine/integrations/message-queue/message-queue.explorer.ts b/packages/twenty-server/src/engine/integrations/message-queue/message-queue.explorer.ts index d196247cfa1db..768e2c47bb3c9 100644 --- a/packages/twenty-server/src/engine/integrations/message-queue/message-queue.explorer.ts +++ b/packages/twenty-server/src/engine/integrations/message-queue/message-queue.explorer.ts @@ -12,6 +12,8 @@ import { MessageQueueWorkerOptions } from 'src/engine/integrations/message-queue import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; import { getQueueToken } from 'src/engine/integrations/message-queue/utils/get-queue-token.util'; +import { ExceptionHandlerService } from 'src/engine/integrations/exception-handler/exception-handler.service'; +import { shouldFilterException } from 'src/engine/utils/global-exception-handler.util'; import { MessageQueueMetadataAccessor } from './message-queue-metadata.accessor'; @@ -25,6 +27,7 @@ export class MessageQueueExplorer implements OnModuleInit { private readonly discoveryService: DiscoveryService, private readonly metadataAccessor: MessageQueueMetadataAccessor, private readonly metadataScanner: MetadataScanner, + private readonly exceptionHandlerService: ExceptionHandlerService, ) {} onModuleInit() { @@ -147,7 +150,14 @@ export class MessageQueueExplorer implements OnModuleInit { for (const [methodName, metadata] of processMetadataCollection) { if (job.name === metadata?.jobName || !metadata?.jobName) { - await contextInstance[methodName].call(contextInstance, job); + try { + await contextInstance[methodName].call(contextInstance, job); + } catch (err) { + if (!shouldFilterException(err)) { + this.exceptionHandlerService.captureExceptions([err]); + } + throw err; + } } } }, options); @@ -155,7 +165,14 @@ export class MessageQueueExplorer implements OnModuleInit { queue.work(async (job) => { for (const [methodName, metadata] of processMetadataCollection) { if (job.name === metadata?.jobName || !metadata?.jobName) { - await instance[methodName].call(instance, job); + try { + await instance[methodName].call(instance, job); + } catch (err) { + if (!shouldFilterException(err)) { + this.exceptionHandlerService.captureExceptions([err]); + } + throw err; + } } } }, options);