diff --git a/packages/nocodb/src/Noco.ts b/packages/nocodb/src/Noco.ts index 994d732dfc..7b0ea06d9f 100644 --- a/packages/nocodb/src/Noco.ts +++ b/packages/nocodb/src/Noco.ts @@ -121,7 +121,7 @@ export default class Noco { nestApp.use(requestIp.mw()); nestApp.use(cookieParser()); - this.initSentry(nestApp); + // this.initSentry(nestApp); nestApp.useWebSocketAdapter(new IoAdapter(httpServer)); @@ -139,7 +139,7 @@ export default class Noco { server.get('/', (_req, res) => res.redirect(dashboardPath)); } - this.initSentryErrorHandler(server); + // this.initSentryErrorHandler(server); return nestApp.getHttpAdapter().getInstance(); } @@ -189,19 +189,19 @@ export default class Noco { } process.env.NC_SERVER_UUID = serverId; } - - private static initSentryErrorHandler(router) { - if (process.env.NC_SENTRY_DSN) { - router.use(Sentry.Handlers.errorHandler()); - } - } - - private static initSentry(router) { - if (process.env.NC_SENTRY_DSN) { - Sentry.init({ dsn: process.env.NC_SENTRY_DSN }); - - // The request handler must be the first middleware on the app - router.use(Sentry.Handlers.requestHandler()); - } - } + // + // private static initSentryErrorHandler(router) { + // if (process.env.NC_SENTRY_DSN) { + // router.use(Sentry.Handlers.errorHandler()); + // } + // } + // + // private static initSentry(router) { + // if (process.env.NC_SENTRY_DSN) { + // Sentry.init({ dsn: process.env.NC_SENTRY_DSN }); + // + // // The request handler must be the first middleware on the app + // router.use(Sentry.Handlers.requestHandler()); + // } + // } } diff --git a/packages/nocodb/src/app.module.ts b/packages/nocodb/src/app.module.ts index 1a944c37f1..493b9b0c9f 100644 --- a/packages/nocodb/src/app.module.ts +++ b/packages/nocodb/src/app.module.ts @@ -3,6 +3,7 @@ import { APP_FILTER, APP_GUARD } from '@nestjs/core'; // @ts-ignore import { ConfigModule } from '@nestjs/config'; import { EventEmitterModule as NestJsEventEmitter } from '@nestjs/event-emitter'; +import { SentryModule } from '@ntegral/nestjs-sentry'; import type { MiddlewareConsumer } from '@nestjs/common'; import { GlobalExceptionFilter } from '~/filters/global-exception/global-exception.filter'; import { GlobalMiddleware } from '~/middlewares/global/global.middleware'; @@ -24,6 +25,7 @@ import { HookHandlerService } from '~/services/hook-handler.service'; import { BasicStrategy } from '~/strategies/basic.strategy/basic.strategy'; import { UsersModule } from '~/modules/users/users.module'; import { AuthModule } from '~/modules/auth/auth.module'; +import {packageInfo} from "~/utils/packageVersion"; export const ceModuleConfig = { imports: [ @@ -39,6 +41,17 @@ export const ceModuleConfig = { load: [() => appConfig], isGlobal: true, }), + ...(process.env.NC_SENTRY_DSN + ? [ + SentryModule.forRoot({ + dsn: process.env.NC_SENTRY_DSN, + debug: false, + environment: process.env.NODE_ENV, + release: packageInfo.version, // must create a release in sentry.io dashboard + logLevels: ['debug'], //based on sentry.io loglevel // + }), + ] + : []), ], providers: [ AuthService, diff --git a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts index f1576cfa9d..ef3d2268aa 100644 --- a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts +++ b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts @@ -1,4 +1,5 @@ -import { Catch, Logger, NotFoundException } from '@nestjs/common'; +import { Catch, Logger, NotFoundException, Optional } from '@nestjs/common'; +import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry'; import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'; import type { Response } from 'express'; import { @@ -15,6 +16,10 @@ import { @Catch() export class GlobalExceptionFilter implements ExceptionFilter { + constructor( + @Optional() @InjectSentry() private readonly client: SentryService, + ) {} + private logger = new Logger(GlobalExceptionFilter.name); catch(exception: any, host: ArgumentsHost) { @@ -90,6 +95,8 @@ export class GlobalExceptionFilter implements ExceptionFilter { if (exception.getStatus?.()) { response.status(exception.getStatus()).json(exception.getResponse()); } else { + this.client?.instance().captureException(exception); + // todo: change the response code response.status(400).json({ msg: exception.message,