mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-20 23:13:23 +10:00
integrate sentry for error logging
This commit is contained in:
+3
-2
@@ -21,6 +21,7 @@
|
||||
"@nestjs/serve-static": "^3.0.0",
|
||||
"@nestjs/terminus": "^9.1.3",
|
||||
"@nestjs/typeorm": "^9.0.1",
|
||||
"@sentry/node": "^7.21.1",
|
||||
"@types/passport": "^1.0.11",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"cache-manager": "^5.1.3",
|
||||
@@ -41,7 +42,7 @@
|
||||
"passport-local": "^1.0.0",
|
||||
"pdf-lib": "^1.17.1",
|
||||
"pg": "^8.8.0",
|
||||
"playwright-chromium": "^1.28.0",
|
||||
"playwright-chromium": "^1.28.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^7.5.7",
|
||||
@@ -55,7 +56,7 @@
|
||||
"@types/bcryptjs": "^2.4.2",
|
||||
"@types/cookie-parser": "^1.4.3",
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/lodash": "^4.14.189",
|
||||
"@types/lodash": "^4.14.190",
|
||||
"@types/multer": "^1.4.7",
|
||||
"@types/node": "^18.11.9",
|
||||
"@types/nodemailer": "^6.4.6",
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
defaults.project=server
|
||||
defaults.org=reactive-resume
|
||||
defaults.url=https://sentry.io/
|
||||
@@ -11,6 +11,7 @@ import { HttpExceptionFilter } from './filters/http-exception.filter';
|
||||
import { FontsModule } from './fonts/fonts.module';
|
||||
import { HealthModule } from './health/health.module';
|
||||
import { IntegrationsModule } from './integrations/integrations.module';
|
||||
import { SentryInterceptor } from './interceptors/sentry.interceptor';
|
||||
import { MailModule } from './mail/mail.module';
|
||||
import { PrinterModule } from './printer/printer.module';
|
||||
import { ResumeModule } from './resume/resume.module';
|
||||
@@ -40,6 +41,10 @@ import { UsersModule } from './users/users.module';
|
||||
provide: APP_INTERCEPTOR,
|
||||
useClass: ClassSerializerInterceptor,
|
||||
},
|
||||
{
|
||||
provide: APP_INTERCEPTOR,
|
||||
useClass: SentryInterceptor,
|
||||
},
|
||||
{
|
||||
provide: APP_FILTER,
|
||||
useClass: HttpExceptionFilter,
|
||||
|
||||
@@ -7,6 +7,7 @@ import authConfig from './auth.config';
|
||||
import cacheConfig from './cache.config';
|
||||
import databaseConfig from './database.config';
|
||||
import googleConfig from './google.config';
|
||||
import loggingConfig from './logging.config';
|
||||
import mailConfig from './mail.config';
|
||||
import storageConfig from './storage.config';
|
||||
|
||||
@@ -58,12 +59,24 @@ const validationSchema = Joi.object({
|
||||
PDF_DELETION_TIME: Joi.number()
|
||||
.default(4 * 24 * 60 * 60 * 1000) // 4 days
|
||||
.allow(''),
|
||||
|
||||
// Logging
|
||||
SERVER_SENTRY_DSN: Joi.string().allow(''),
|
||||
});
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
NestConfigModule.forRoot({
|
||||
load: [appConfig, authConfig, cacheConfig, databaseConfig, googleConfig, mailConfig, storageConfig],
|
||||
load: [
|
||||
appConfig,
|
||||
authConfig,
|
||||
cacheConfig,
|
||||
databaseConfig,
|
||||
googleConfig,
|
||||
mailConfig,
|
||||
storageConfig,
|
||||
loggingConfig,
|
||||
],
|
||||
validationSchema: validationSchema,
|
||||
}),
|
||||
],
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { registerAs } from '@nestjs/config';
|
||||
|
||||
export default registerAs('logging', () => ({
|
||||
sentryDSN: process.env.SERVER_SENTRY_DSN,
|
||||
}));
|
||||
@@ -0,0 +1,15 @@
|
||||
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class SentryInterceptor implements NestInterceptor {
|
||||
intercept(_context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||
return next.handle().pipe(
|
||||
tap(null, (exception) => {
|
||||
Sentry.captureException(exception);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -2,12 +2,14 @@ import { Logger, ValidationPipe } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import cookieParser from 'cookie-parser';
|
||||
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
const bootstrap = async () => {
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||
const configService = app.get(ConfigService);
|
||||
|
||||
// Middleware
|
||||
app.enableCors({ credentials: true });
|
||||
@@ -17,9 +19,11 @@ const bootstrap = async () => {
|
||||
// Pipes
|
||||
app.useGlobalPipes(new ValidationPipe({ transform: true }));
|
||||
|
||||
const configService = app.get(ConfigService);
|
||||
const port = configService.get<number>('app.port');
|
||||
// Error Logging
|
||||
Sentry.init({ dsn: configService.get<string>('logging.sentryDSN') });
|
||||
|
||||
// Server Port
|
||||
const port = configService.get<number>('app.port');
|
||||
await app.listen(port);
|
||||
|
||||
Logger.log(`🚀 Server is up and running!`);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
import { Controller, Get, InternalServerErrorException, Param, Query } from '@nestjs/common';
|
||||
|
||||
import { PrinterService } from './printer.service';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user