caught-exception
Create Exception Filter
src/config/caught-exception/caught-exception.filter.ts
import { Catch, HttpException, Injectable } from '@nestjs/common';
import { HttpExceptionFilter } from 'caught-exception';
import dataDogTracer from './config/datadog/tracer';
@Injectable()
@Catch(HttpException)
export class HttpExceptionFilterInject extends HttpExceptionFilter {
dataDogTracer = dataDogTracer;
}
Global Caught Exception Filter
src/main.js
require('./config/datadog/tracer');
import { HttpExceptionFilterInject } from './src/config/caught-exception/caught-exception.filter.ts';
async function bootstrap() {
app.useGlobalFilters(new HttpExceptionFilterInject());
}
DataDog file
src/config/datadog/trace.js
import tracer from 'dd-trace';
const dataDogTracer = tracer.init();
export default dataDogTracer;
Intercept all axios Require/Response in development
src/root.module.js
import axios from 'axios';
import dataDogTracer from './src/config/datadog/tracer';
require('caught-exception/dist/common/api/http-request-global.axios')({
axios,
dataDogTracer,
});
Provider HttpExceptionFilterInject on RootModule
src/root.module.js
import { HttpExceptionFilterInject } from './caught-exception';
import { APP_FILTER } from '@nestjs/core';
@Module({
providers: [
{
provide: APP_FILTER,
useClass: HttpExceptionFilterInject,
},
],
});
Caught controllers Require
src/root.module.js
import { LoggerMiddlewareToModule } from './caught-exception';
export class RootModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(LoggerMiddlewareToModule).forRoutes('*');
}
}
Environments
DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL= true
DD_LOGS_ENABLED= true
DD_LOGS_INJECTION= true
DD_PROCESS_CONFIG_ENABLED= true
DD_PROFILING_ENABLE= true
DD_TRACE_ANALYTICS_ENABLED= false
DD_TRACE_ENABLED= true
DD_TRACE_HEADER_TAGS= Host:origin,Referer:referer,x-forwarded-for:x-forwarded-for
DD_VERSION= 4.14.0
CATCH_EXCEPTION_TRACE_ROUTES_RULES= { "intercept": { } }
CATCH_EXCEPTION_TRACE_ROUTES_RULES= { "intercept": { "include": ["login"], "exclude": ["document"] } }
CATCH_EXCEPTION_TRACE_ROUTES_RULES= { "intercept": { "production": true } }