Browse Source

fix: correction in sentry integration

pull/6718/head
Pranav C 1 year ago
parent
commit
9149c5b28f
  1. 34
      packages/nocodb/src/Noco.ts
  2. 13
      packages/nocodb/src/app.module.ts
  3. 9
      packages/nocodb/src/filters/global-exception/global-exception.filter.ts

34
packages/nocodb/src/Noco.ts

@ -121,7 +121,7 @@ export default class Noco {
nestApp.use(requestIp.mw()); nestApp.use(requestIp.mw());
nestApp.use(cookieParser()); nestApp.use(cookieParser());
this.initSentry(nestApp); // this.initSentry(nestApp);
nestApp.useWebSocketAdapter(new IoAdapter(httpServer)); nestApp.useWebSocketAdapter(new IoAdapter(httpServer));
@ -139,7 +139,7 @@ export default class Noco {
server.get('/', (_req, res) => res.redirect(dashboardPath)); server.get('/', (_req, res) => res.redirect(dashboardPath));
} }
this.initSentryErrorHandler(server); // this.initSentryErrorHandler(server);
return nestApp.getHttpAdapter().getInstance(); return nestApp.getHttpAdapter().getInstance();
} }
@ -189,19 +189,19 @@ export default class Noco {
} }
process.env.NC_SERVER_UUID = serverId; process.env.NC_SERVER_UUID = serverId;
} }
//
private static initSentryErrorHandler(router) { // private static initSentryErrorHandler(router) {
if (process.env.NC_SENTRY_DSN) { // if (process.env.NC_SENTRY_DSN) {
router.use(Sentry.Handlers.errorHandler()); // router.use(Sentry.Handlers.errorHandler());
} // }
} // }
//
private static initSentry(router) { // private static initSentry(router) {
if (process.env.NC_SENTRY_DSN) { // if (process.env.NC_SENTRY_DSN) {
Sentry.init({ dsn: process.env.NC_SENTRY_DSN }); // Sentry.init({ dsn: process.env.NC_SENTRY_DSN });
//
// The request handler must be the first middleware on the app // // The request handler must be the first middleware on the app
router.use(Sentry.Handlers.requestHandler()); // router.use(Sentry.Handlers.requestHandler());
} // }
} // }
} }

13
packages/nocodb/src/app.module.ts

@ -3,6 +3,7 @@ import { APP_FILTER, APP_GUARD } from '@nestjs/core';
// @ts-ignore // @ts-ignore
import { ConfigModule } from '@nestjs/config'; import { ConfigModule } from '@nestjs/config';
import { EventEmitterModule as NestJsEventEmitter } from '@nestjs/event-emitter'; import { EventEmitterModule as NestJsEventEmitter } from '@nestjs/event-emitter';
import { SentryModule } from '@ntegral/nestjs-sentry';
import type { MiddlewareConsumer } from '@nestjs/common'; import type { MiddlewareConsumer } from '@nestjs/common';
import { GlobalExceptionFilter } from '~/filters/global-exception/global-exception.filter'; import { GlobalExceptionFilter } from '~/filters/global-exception/global-exception.filter';
import { GlobalMiddleware } from '~/middlewares/global/global.middleware'; 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 { BasicStrategy } from '~/strategies/basic.strategy/basic.strategy';
import { UsersModule } from '~/modules/users/users.module'; import { UsersModule } from '~/modules/users/users.module';
import { AuthModule } from '~/modules/auth/auth.module'; import { AuthModule } from '~/modules/auth/auth.module';
import {packageInfo} from "~/utils/packageVersion";
export const ceModuleConfig = { export const ceModuleConfig = {
imports: [ imports: [
@ -39,6 +41,17 @@ export const ceModuleConfig = {
load: [() => appConfig], load: [() => appConfig],
isGlobal: true, 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: [ providers: [
AuthService, AuthService,

9
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 { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
import type { Response } from 'express'; import type { Response } from 'express';
import { import {
@ -15,6 +16,10 @@ import {
@Catch() @Catch()
export class GlobalExceptionFilter implements ExceptionFilter { export class GlobalExceptionFilter implements ExceptionFilter {
constructor(
@Optional() @InjectSentry() private readonly client: SentryService,
) {}
private logger = new Logger(GlobalExceptionFilter.name); private logger = new Logger(GlobalExceptionFilter.name);
catch(exception: any, host: ArgumentsHost) { catch(exception: any, host: ArgumentsHost) {
@ -90,6 +95,8 @@ export class GlobalExceptionFilter implements ExceptionFilter {
if (exception.getStatus?.()) { if (exception.getStatus?.()) {
response.status(exception.getStatus()).json(exception.getResponse()); response.status(exception.getStatus()).json(exception.getResponse());
} else { } else {
this.client?.instance().captureException(exception);
// todo: change the response code // todo: change the response code
response.status(400).json({ response.status(400).json({
msg: exception.message, msg: exception.message,

Loading…
Cancel
Save