From b8d0ae343126ac3d42ef4fbd3d923d6c2d47de8c Mon Sep 17 00:00:00 2001 From: Jay McDoniel Date: Sat, 5 Nov 2022 12:28:00 -0700 Subject: [PATCH] feat: create new service for logging metadata from filter The new `OgmaFilterLogger` an be injected into a service and take in an exception and an arguments host object from Nest and print out metadata according to how the request failed. This will **only** happen, however, if the request has not been logged by an interceptor, meaning there will not be double logging of requests which would make logs noiser. This is done by checking for the existence of the `requestId` added by the interceptor earlier in the call, and the major gain here is that now errors caused by guards or middleware can be caught can logged just as other requests are properly automatically logged as well, making Ogma now fully capable of logging **any** request type into Nest! This feature is opt-in, just as the interceptor is, but the power it brings is major due to now not leaving any requests unlogged. The only downside at the moment is not being able to determing the time length of the request as most underlying transports don't grab the metadata of the start time, but there will be mentions of how users can implement such a feature to allow for that if they so choose. --- integration/src/gql/exception.filter.ts | 16 ++++++ integration/src/gql/gql.resolver.ts | 11 ++++- integration/src/gql/logger.filter.ts | 0 integration/src/http/error-logging.filter.ts | 15 ++++++ integration/src/http/http.controller.ts | 11 +++++ .../src/rpc/client/rpc-client.controller.ts | 6 +++ .../src/rpc/server/rpc-server.controller.ts | 10 +++- integration/src/shared/exception.filter.ts | 10 ++-- integration/src/shared/fail.guard.ts | 8 +++ .../src/shared/server-exception.filter.ts | 9 +++- integration/src/ws/ws.filter.ts | 13 +++-- integration/src/ws/ws.gateway.ts | 10 +++- integration/test/gql.spec.ts | 22 +++++++-- integration/test/http.spec.ts | 20 ++++++-- integration/test/rpc.spec.ts | 25 ++++++++-- integration/test/utils/index.ts | 16 ++++-- integration/test/ws.spec.ts | 22 ++++++++- .../src/filter/ogma-filter.logger.ts | 49 +++++++++++++++++++ packages/nestjs-module/src/index.ts | 1 + .../interceptor-service.interface.ts | 8 +-- .../providers/abstract-interceptor.service.ts | 30 +++++++----- .../providers/delegator.service.ts | 20 ++++++-- .../providers/gql-interceptor.service.ts | 15 ++++-- .../providers/http-interceptor.service.ts | 22 ++++++--- .../providers/rpc-interceptor.service.ts | 15 ++++-- .../websocket-interceptor.service.ts | 13 ++++- .../nestjs-module/src/ogma-core.module.ts | 3 ++ .../src/express-interceptor.service.ts | 5 -- .../src/fastify-interceptor.service.ts | 5 -- .../src/grpc-interceptor.service.ts | 5 -- .../src/kafka-interceptor.service.ts | 5 -- .../src/mqtt-interceptor.service.ts | 5 -- .../src/nats-interceptor.service.ts | 5 -- .../src/rabbitmq-interceptor.service.ts | 5 -- .../src/redis-interceptor.service.ts | 5 -- .../src/socket-io-interceptor.service.ts | 5 -- .../src/tcp-interceptor.service.ts | 5 -- .../platform-ws/src/ws-interceptor.service.ts | 5 -- 38 files changed, 336 insertions(+), 119 deletions(-) create mode 100644 integration/src/gql/exception.filter.ts create mode 100644 integration/src/gql/logger.filter.ts create mode 100644 integration/src/http/error-logging.filter.ts create mode 100644 integration/src/shared/fail.guard.ts create mode 100644 packages/nestjs-module/src/filter/ogma-filter.logger.ts diff --git a/integration/src/gql/exception.filter.ts b/integration/src/gql/exception.filter.ts new file mode 100644 index 000000000..75d32be12 --- /dev/null +++ b/integration/src/gql/exception.filter.ts @@ -0,0 +1,16 @@ +import { + ArgumentsHost, + Catch, + ExceptionFilter as NestExceptionFilter, + HttpException, +} from '@nestjs/common'; +import { OgmaFilterLogger } from '@ogma/nestjs-module'; + +@Catch() +export class ExceptionFilter implements NestExceptionFilter { + constructor(private readonly service: OgmaFilterLogger) {} + catch(exception: HttpException, host: ArgumentsHost) { + this.service.log(exception, host); + return exception; + } +} diff --git a/integration/src/gql/gql.resolver.ts b/integration/src/gql/gql.resolver.ts index 84be66d50..8be9f5301 100644 --- a/integration/src/gql/gql.resolver.ts +++ b/integration/src/gql/gql.resolver.ts @@ -1,11 +1,14 @@ -import { BadRequestException } from '@nestjs/common'; +import { BadRequestException, UseFilters, UseGuards } from '@nestjs/common'; import { Mutation, Query, Resolver } from '@nestjs/graphql'; import { OgmaSkip } from '@ogma/nestjs-module'; import { AppService } from '../app.service'; +import { FailGuard } from '../shared/fail.guard'; +import { ExceptionFilter } from './exception.filter'; import { SimpleObject } from './simple-object.model'; @Resolver(() => SimpleObject) +@UseFilters(ExceptionFilter) export class GqlResolver { constructor(private readonly appService: AppService) {} @@ -29,4 +32,10 @@ export class GqlResolver { getSkip(): SimpleObject { return this.appService.getHello(); } + + @Query(() => SimpleObject) + @UseGuards(FailGuard) + failGuard(): SimpleObject { + return this.appService.getHello(); + } } diff --git a/integration/src/gql/logger.filter.ts b/integration/src/gql/logger.filter.ts new file mode 100644 index 000000000..e69de29bb diff --git a/integration/src/http/error-logging.filter.ts b/integration/src/http/error-logging.filter.ts new file mode 100644 index 000000000..662c9d15f --- /dev/null +++ b/integration/src/http/error-logging.filter.ts @@ -0,0 +1,15 @@ +import { ArgumentsHost, Catch } from '@nestjs/common'; +import { BaseExceptionFilter } from '@nestjs/core'; +import { OgmaFilterLogger } from '@ogma/nestjs-module'; + +@Catch() +export class ErrorLoggingFilter extends BaseExceptionFilter { + constructor(private readonly logger: OgmaFilterLogger) { + super(); + } + + catch(exception: Error, host: ArgumentsHost) { + this.logger.log(exception, host); + return super.catch(exception, host); + } +} diff --git a/integration/src/http/http.controller.ts b/integration/src/http/http.controller.ts index 4f89ba8ec..f0a4721aa 100644 --- a/integration/src/http/http.controller.ts +++ b/integration/src/http/http.controller.ts @@ -7,13 +7,18 @@ import { Patch, Post, Put, + UseFilters, + UseGuards, } from '@nestjs/common'; import { OgmaSkip } from '@ogma/nestjs-module'; import { AppService } from '../app.service'; +import { FailGuard } from '../shared/fail.guard'; import { SimpleObject } from '../simple-object.model'; +import { ErrorLoggingFilter } from './error-logging.filter'; @Controller() +@UseFilters(ErrorLoggingFilter) export class HttpController { constructor(private readonly appService: AppService) {} @@ -39,6 +44,12 @@ export class HttpController { return this.appService.getHello(); } + @Get('fail-guard') + @UseGuards(FailGuard) + failGuard() { + /* no op */ + } + @Post() getPost(): SimpleObject { return this.appService.getHello(); diff --git a/integration/src/rpc/client/rpc-client.controller.ts b/integration/src/rpc/client/rpc-client.controller.ts index be8a44e8f..b331af65e 100644 --- a/integration/src/rpc/client/rpc-client.controller.ts +++ b/integration/src/rpc/client/rpc-client.controller.ts @@ -26,4 +26,10 @@ export class RpcClientController implements OnApplicationBootstrap { getSkip() { return this.micro.send({ cmd: 'skip' }, { ip: '127.0.0.1' }); } + + @Get('fail-guard') + @UseFilters(ExceptionFilter) + failGuard() { + return this.micro.send({ cmd: 'fail-guard' }, { ip: '127.0.0.1' }); + } } diff --git a/integration/src/rpc/server/rpc-server.controller.ts b/integration/src/rpc/server/rpc-server.controller.ts index a84a733cd..4be2094a0 100644 --- a/integration/src/rpc/server/rpc-server.controller.ts +++ b/integration/src/rpc/server/rpc-server.controller.ts @@ -1,8 +1,9 @@ -import { BadRequestException, Controller, UseFilters } from '@nestjs/common'; +import { BadRequestException, Controller, UseFilters, UseGuards } from '@nestjs/common'; import { MessagePattern } from '@nestjs/microservices'; import { OgmaSkip } from '@ogma/nestjs-module'; import { AppService } from '../../app.service'; +import { FailGuard } from '../../shared/fail.guard'; import { ExceptionFilter } from './../../shared/server-exception.filter'; @Controller() @@ -25,4 +26,11 @@ export class RpcServerController { getSkip() { return this.appService.getHello(); } + + @MessagePattern({ cmd: 'fail-guard' }) + @UseFilters(ExceptionFilter) + @UseGuards(FailGuard) + failGuard() { + /* no op */ + } } diff --git a/integration/src/shared/exception.filter.ts b/integration/src/shared/exception.filter.ts index ed54c5167..c6e897319 100644 --- a/integration/src/shared/exception.filter.ts +++ b/integration/src/shared/exception.filter.ts @@ -1,8 +1,12 @@ -import { ArgumentsHost, Catch, HttpException } from '@nestjs/common'; -import { BaseExceptionFilter } from '@nestjs/core'; +import { + ArgumentsHost, + Catch, + ExceptionFilter as NestExceptionFilter, + HttpException, +} from '@nestjs/common'; @Catch() -export class ExceptionFilter extends BaseExceptionFilter { +export class ExceptionFilter implements NestExceptionFilter { catch(exception: HttpException, host: ArgumentsHost) { const res = host.switchToHttp().getResponse(); res.send(exception); diff --git a/integration/src/shared/fail.guard.ts b/integration/src/shared/fail.guard.ts new file mode 100644 index 000000000..d3531e9d1 --- /dev/null +++ b/integration/src/shared/fail.guard.ts @@ -0,0 +1,8 @@ +import { CanActivate, Injectable } from '@nestjs/common'; + +@Injectable() +export class FailGuard implements CanActivate { + canActivate() { + return false; + } +} diff --git a/integration/src/shared/server-exception.filter.ts b/integration/src/shared/server-exception.filter.ts index dde87394d..fad083768 100644 --- a/integration/src/shared/server-exception.filter.ts +++ b/integration/src/shared/server-exception.filter.ts @@ -1,10 +1,15 @@ -import { Catch, HttpException } from '@nestjs/common'; +import { ArgumentsHost, Catch, HttpException, Optional } from '@nestjs/common'; import { BaseRpcExceptionFilter } from '@nestjs/microservices'; +import { OgmaFilterLogger } from '@ogma/nestjs-module'; import { Observable, throwError } from 'rxjs'; @Catch() export class ExceptionFilter extends BaseRpcExceptionFilter { - catch(exception: HttpException): Observable { + constructor(@Optional() private readonly service?: OgmaFilterLogger) { + super(); + } + catch(exception: HttpException, host: ArgumentsHost): Observable { + this.service?.log(exception, host); return throwError(() => exception); } } diff --git a/integration/src/ws/ws.filter.ts b/integration/src/ws/ws.filter.ts index f84978f57..2320d0e67 100644 --- a/integration/src/ws/ws.filter.ts +++ b/integration/src/ws/ws.filter.ts @@ -1,9 +1,16 @@ -import { ArgumentsHost, Catch, HttpException } from '@nestjs/common'; -import { BaseWsExceptionFilter } from '@nestjs/websockets'; +import { + ArgumentsHost, + Catch, + ExceptionFilter as NestExceptionFilter, + HttpException, +} from '@nestjs/common'; +import { OgmaFilterLogger } from '@ogma/nestjs-module'; @Catch() -export class ExceptionFilter extends BaseWsExceptionFilter { +export class ExceptionFilter implements NestExceptionFilter { + constructor(private readonly service: OgmaFilterLogger) {} catch(exception: HttpException, host: ArgumentsHost) { + this.service.log(exception, host); const client = host.switchToWs().getClient(); if (client._isServer) { return client.send('exception'); diff --git a/integration/src/ws/ws.gateway.ts b/integration/src/ws/ws.gateway.ts index 1126ae8b4..75a01d053 100644 --- a/integration/src/ws/ws.gateway.ts +++ b/integration/src/ws/ws.gateway.ts @@ -1,8 +1,9 @@ -import { BadRequestException, UseFilters, UseInterceptors } from '@nestjs/common'; +import { BadRequestException, UseFilters, UseGuards, UseInterceptors } from '@nestjs/common'; import { SubscribeMessage, WebSocketGateway } from '@nestjs/websockets'; import { OgmaInterceptor, OgmaSkip } from '@ogma/nestjs-module'; import { AppService } from '../app.service'; +import { FailGuard } from '../shared/fail.guard'; import { SimpleObject } from '../simple-object.model'; import { ExceptionFilter } from './ws.filter'; @@ -27,4 +28,11 @@ export class WsGateway { getSkip(): { event: string; data: SimpleObject } { return { event: 'message', data: this.appService.getHello() }; } + + @SubscribeMessage('fail-guard') + @UseGuards(FailGuard) + @UseFilters(ExceptionFilter) + failGuard(): void { + /* no op */ + } } diff --git a/integration/test/gql.spec.ts b/integration/test/gql.spec.ts index e484a8a4e..70ef4dadd 100644 --- a/integration/test/gql.spec.ts +++ b/integration/test/gql.spec.ts @@ -3,7 +3,7 @@ import { INestApplication } from '@nestjs/common'; import { MercuriusDriver } from '@nestjs/mercurius'; import { ExpressAdapter } from '@nestjs/platform-express'; import { FastifyAdapter } from '@nestjs/platform-fastify'; -import { OgmaInterceptor, OgmaService } from '@ogma/nestjs-module'; +import { OgmaFilterLogger, OgmaInterceptor, OgmaService } from '@ogma/nestjs-module'; import { GraphQLParser } from '@ogma/platform-graphql'; import { GraphQLFastifyParser } from '@ogma/platform-graphql-fastify'; import { style } from '@ogma/styler'; @@ -39,11 +39,13 @@ for (const { adapter, server, parser, driver } of [ const GqlParserSuite = suite<{ app: INestApplication; logSpy: Stub; - logs: Parameters[]; + logs: Parameters[]; + filterSpy: Stub; }>(`${server} GraphQL server`, { app: undefined, logSpy: undefined, logs: [], + filterSpy: undefined, }); GqlParserSuite.before(async (context) => { const modRef = await createTestModule(GqlModule.forFeature(driver), { @@ -54,14 +56,18 @@ for (const { adapter, server, parser, driver } of [ }); context.app = modRef.createNestApplication(adapter); const interceptor = context.app.get(OgmaInterceptor); + const filterService = context.app.get(OgmaFilterLogger); await context.app.listen(0); const baseUrl = await context.app.getUrl(); request.setBaseUrl(baseUrl.replace('[::1]', 'localhost')); context.logSpy = stubMethod(interceptor, 'log'); + context.filterSpy = stubMethod(filterService as any, 'doLog'); }); - GqlParserSuite.after.each(({ logSpy, logs }) => { + GqlParserSuite.after.each(({ logSpy, logs, filterSpy }) => { logSpy.firstCall && logs.push(logSpy.firstCall.args); logSpy.reset(); + filterSpy.firstCall && logs.push(filterSpy.firstCall.args); + filterSpy.reset(); }); GqlParserSuite.after(async ({ app, logs }) => { const ogma = app.get(OgmaService); @@ -97,5 +103,15 @@ for (const { adapter, server, parser, driver } of [ await spec().post('/graphql').withGraphQLQuery('query getSkip{ getSkip{ hello }}').toss(); is(logSpy.callCount, 0); }); + GqlParserSuite('it should error at the guard and still log a line', async ({ filterSpy }) => { + await spec().post('/graphql').withGraphQLQuery('query failGuard { failGuard { hello }}').toss(); + toBeALogObject( + filterSpy.firstCall.args[0], + 'query', + '/graphql', + 'HTTP/1.1', + style.yellow.apply(403), + ); + }); GqlParserSuite.run(); } diff --git a/integration/test/http.spec.ts b/integration/test/http.spec.ts index 4202e052f..2109a9d2b 100644 --- a/integration/test/http.spec.ts +++ b/integration/test/http.spec.ts @@ -1,7 +1,7 @@ import { INestApplication } from '@nestjs/common'; import { ExpressAdapter } from '@nestjs/platform-express'; import { FastifyAdapter } from '@nestjs/platform-fastify'; -import { OgmaInterceptor, OgmaService } from '@ogma/nestjs-module'; +import { OgmaFilterLogger, OgmaInterceptor, OgmaService } from '@ogma/nestjs-module'; import { ExpressParser } from '@ogma/platform-express'; import { FastifyParser } from '@ogma/platform-fastify'; import { style } from '@ogma/styler'; @@ -19,13 +19,13 @@ import { toBeALogObject, } from './utils'; -const expectRequestId = (spy: Stub) => { +const expectRequestId = (spy: Stub | Stub) => { is(typeof spy.firstCall.args[2], 'string'); is(spy.firstCall.args[2].length, 16); }; const expectLogObject = ( - spy: Stub, + spy: Stub | Stub, method: string, endpoint: string, status: string, @@ -49,11 +49,13 @@ for (const { adapter, server, parser } of [ const HttpSuite = suite<{ app: INestApplication; logSpy: Stub; - logs: Parameters[]; + logs: Parameters[]; + filterSpy: Stub; }>(`${server} HTTP Log Suite`, { app: undefined, logSpy: undefined, logs: [], + filterSpy: undefined, }); HttpSuite.before(async (context) => { const modRef = await createTestModule(HttpServerModule, { @@ -62,18 +64,22 @@ for (const { adapter, server, parser } of [ }); context.app = modRef.createNestApplication(adapter); const interceptor = context.app.get(OgmaInterceptor); + const filterService = context.app.get(OgmaFilterLogger); await context.app.listen(0); request.setBaseUrl((await context.app.getUrl()).replace('[::1]', 'localhost')); context.logSpy = stubMethod(interceptor, 'log'); + context.filterSpy = stubMethod(filterService as any, 'doLog'); }); HttpSuite.after(async ({ app, logs }) => { const ogma = app.get(OgmaService); await app.close(); reportValues(ogma, logs); }); - HttpSuite.after.each(({ logSpy, logs }) => { + HttpSuite.after.each(({ logSpy, logs, filterSpy }) => { logSpy.firstCall && logs.push(logSpy.firstCall.args); logSpy.reset(); + filterSpy.firstCall && logs.push(filterSpy.firstCall.args); + filterSpy.reset(); }); for (const { method, status } of [ { @@ -108,5 +114,9 @@ for (const { adapter, server, parser } of [ await spec().get('/skip').expectBody(hello).expectStatus(200); is(logSpy.callCount, 0); }); + HttpSuite('It should get caught by a guard but still be able to log', async ({ filterSpy }) => { + await spec().get('/fail-guard').expectStatus(403); + expectLogObject(filterSpy, 'GET', '/fail-guard', style.yellow.apply(403)); + }); HttpSuite.run(); } diff --git a/integration/test/rpc.spec.ts b/integration/test/rpc.spec.ts index 5bb474e10..4f50f32f5 100644 --- a/integration/test/rpc.spec.ts +++ b/integration/test/rpc.spec.ts @@ -9,7 +9,7 @@ import { Transport, } from '@nestjs/microservices'; import { Test } from '@nestjs/testing'; -import { OgmaInterceptor, OgmaService } from '@ogma/nestjs-module'; +import { OgmaFilterLogger, OgmaInterceptor, OgmaService } from '@ogma/nestjs-module'; import { MqttParser } from '@ogma/platform-mqtt'; import { NatsParser } from '@ogma/platform-nats'; import { RabbitMqParser } from '@ogma/platform-rabbitmq'; @@ -84,14 +84,16 @@ for (const { server, transport, options, protocol, parser } of [ ] as const) { const RpcSuite = suite<{ logSpy: Stub; - logs: Parameters[]; + logs: Parameters[]; rpcServer: INestMicroservice; rpcClient: INestApplication; + filterSpy: Stub; }>(`${server} interceptor suite`, { logs: [], logSpy: undefined, rpcClient: undefined, rpcServer: undefined, + filterSpy: undefined, }); RpcSuite.before(async (context) => { const modRef = await createTestModule(RpcServerModule, { @@ -105,6 +107,7 @@ for (const { server, transport, options, protocol, parser } of [ options, } as any); const interceptor = rpcServer.get(OgmaInterceptor); + const filterService = rpcServer.get(OgmaFilterLogger); await rpcServer.listen().catch(console.error); const clientRef = await Test.createTestingModule({ imports: [ @@ -119,12 +122,15 @@ for (const { server, transport, options, protocol, parser } of [ context.logSpy = stubMethod(interceptor, 'log'); context.rpcClient = rpcClient; context.rpcServer = rpcServer; + context.filterSpy = stubMethod(filterService as any, 'doLog'); const baseUrl = await rpcClient.getUrl(); request.setBaseUrl(baseUrl.replace('[::1]', 'localhost')); }); - RpcSuite.after.each(({ logSpy, logs }) => { + RpcSuite.after.each(({ logSpy, logs, filterSpy }) => { logSpy.firstCall && logs.push(logSpy.firstCall.args); logSpy.reset(); + filterSpy.firstCall && logs.push(filterSpy.firstCall.args); + filterSpy.reset(); }); RpcSuite.after(async ({ logs, rpcClient, rpcServer }) => { const ogma = rpcServer.get(OgmaService); @@ -155,5 +161,18 @@ for (const { server, transport, options, protocol, parser } of [ await spec().get('/skip').expectBody(hello).toss(); is(logSpy.callCount, 0); }); + RpcSuite( + 'it should be caught by a guard in the rpc server and still log', + async ({ filterSpy }) => { + await spec().get('/fail-guard').toss(); + toBeALogObject( + filterSpy.firstCall.args[0], + server, + JSON.stringify({ cmd: 'fail-guard' }), + protocol, + style.red.apply(500), + ); + }, + ); RpcSuite.run(); } diff --git a/integration/test/utils/index.ts b/integration/test/utils/index.ts index 34fcab977..5d61b4a13 100644 --- a/integration/test/utils/index.ts +++ b/integration/test/utils/index.ts @@ -1,4 +1,9 @@ -import { OgmaInterceptor, OgmaService, OgmaServiceOptions } from '@ogma/nestjs-module'; +import { + OgmaFilterLogger, + OgmaInterceptor, + OgmaService, + OgmaServiceOptions, +} from '@ogma/nestjs-module'; const stream = process.stdout; process.stdout.getColorDepth = () => 8; @@ -10,14 +15,19 @@ export const serviceOptionsFactory = (app: string, json = false): OgmaServiceOpt return { application: app, stream, json }; }; -export const reportValues = (ogma: OgmaService, logs: Parameters[]) => { +export const reportValues = ( + ogma: OgmaService, + logs: Parameters[], +) => { if (process.env.CI) { return; } console.log('\n'); for (const log of logs) { ogma.info(log[0], { - context: `${log[1].getClass().name}#${log[1].getHandler().name}`, + context: log[1] + ? `${log[1]?.getClass().name}#${log[1]?.getHandler().name}` + : 'ExceptionFilter', correlationId: log[2] ?? '', }); } diff --git a/integration/test/ws.spec.ts b/integration/test/ws.spec.ts index f32117408..e31ad378d 100644 --- a/integration/test/ws.spec.ts +++ b/integration/test/ws.spec.ts @@ -2,7 +2,7 @@ import { INestApplication } from '@nestjs/common'; import { IoAdapter } from '@nestjs/platform-socket.io'; import { WsAdapter } from '@nestjs/platform-ws'; import { Test } from '@nestjs/testing'; -import { OgmaInterceptor, OgmaService } from '@ogma/nestjs-module'; +import { OgmaFilterLogger, OgmaInterceptor, OgmaService } from '@ogma/nestjs-module'; import { SocketIOParser } from '@ogma/platform-socket.io'; import { WsParser } from '@ogma/platform-ws'; import { style } from '@ogma/styler'; @@ -37,16 +37,18 @@ for (const { adapter, server, parser, client, protocol, sendMethod, serializer } ] as const) { const WsSuite = suite<{ logSpy: Stub; - logs: Parameters[]; + logs: Parameters[]; app: INestApplication; baseUrl: string; wsClient: { send: (message: string) => Promise; close: () => Promise }; + filterSpy: Stub; }>(`${server} interceptor suite`, { logs: [], logSpy: undefined, app: undefined, baseUrl: undefined, wsClient: undefined, + filterSpy: undefined, }); WsSuite.before(async (context) => { const modRef = await Test.createTestingModule({ @@ -62,7 +64,10 @@ for (const { adapter, server, parser, client, protocol, sendMethod, serializer } context.app = modRef.createNestApplication(); context.app.useWebSocketAdapter(new adapter(context.app)); const interceptor = context.app.get(OgmaInterceptor); + const filterService = context.app.get(OgmaFilterLogger); context.logSpy = stubMethod(interceptor, 'log'); + context.filterSpy = stubMethod(filterService as any, 'doLog'); + context.filterSpy.passThrough(); await context.app.listen(0); const baseUrl = await context.app.getUrl(); context.wsClient = await makeWs(client, baseUrl.replace('http', protocol), sendMethod); @@ -99,5 +104,18 @@ for (const { adapter, server, parser, client, protocol, sendMethod, serializer } await wsClient.send(serializer('skip')); is(logSpy.callCount, 0); }); + WsSuite.skip( + 'it should go to the guard and still log the request', + async ({ wsClient, filterSpy }) => { + await wsClient.send(serializer('fail-guard')); + toBeALogObject( + filterSpy.firstCall.args[0], + server.toLowerCase(), + 'fail-guard', + 'WS', + style.red.apply(500), + ); + }, + ); WsSuite.run(); } diff --git a/packages/nestjs-module/src/filter/ogma-filter.logger.ts b/packages/nestjs-module/src/filter/ogma-filter.logger.ts new file mode 100644 index 000000000..67dc5c14a --- /dev/null +++ b/packages/nestjs-module/src/filter/ogma-filter.logger.ts @@ -0,0 +1,49 @@ +import { ArgumentsHost, Injectable } from '@nestjs/common'; +import { OgmaOptions } from '@ogma/logger'; + +import { InjectOgmaInterceptorOptions } from '../decorators'; +import { LogObject } from '../interceptor/interfaces/log.interface'; +import { DelegatorService } from '../interceptor/providers'; +import { OgmaInterceptorOptions } from '../interfaces'; +import { OgmaService } from '../ogma.service'; + +@Injectable() +export class OgmaFilterLogger { + private json: boolean; + private color: boolean; + + constructor( + private readonly service: OgmaService, + private readonly delegator: DelegatorService, + @InjectOgmaInterceptorOptions() private readonly options: OgmaInterceptorOptions, + ) { + const ogmaOptions: OgmaOptions = (this.service as any).ogma.options; + this.json = ogmaOptions.json; + this.color = ogmaOptions.color; + } + + log(exception: Error, host: ArgumentsHost): void { + if (this.hasAlreadyBeenLogged(host)) { + return; + } + const valueToLog = this.delegator.getContextErrorString( + exception, + host, + this.delegator.getStartTime(host), + { + ...this.options, + json: this.json, + color: this.color, + }, + ); + this.doLog(valueToLog.log); + } + + private doLog(valueToLog: string | LogObject): void { + this.service.log(valueToLog, { context: 'ExceptionFilter' }); + } + + private hasAlreadyBeenLogged(host: ArgumentsHost): boolean { + return !!this.delegator.getRequestId(host); + } +} diff --git a/packages/nestjs-module/src/index.ts b/packages/nestjs-module/src/index.ts index f2af0949d..a0df8f232 100644 --- a/packages/nestjs-module/src/index.ts +++ b/packages/nestjs-module/src/index.ts @@ -1,4 +1,5 @@ export * from './decorators'; +export * from './filter/ogma-filter.logger'; export * from './interceptor/ogma.interceptor'; export * from './interceptor/providers'; export * from './interfaces/ogma-options.interface'; diff --git a/packages/nestjs-module/src/interceptor/interfaces/interceptor-service.interface.ts b/packages/nestjs-module/src/interceptor/interfaces/interceptor-service.interface.ts index ce9d2e7a0..f02423e59 100644 --- a/packages/nestjs-module/src/interceptor/interfaces/interceptor-service.interface.ts +++ b/packages/nestjs-module/src/interceptor/interfaces/interceptor-service.interface.ts @@ -1,4 +1,4 @@ -import { ExecutionContext, HttpException } from '@nestjs/common'; +import { ArgumentsHost, ExecutionContext, HttpException } from '@nestjs/common'; import { OgmaInterceptorServiceOptions } from '../../interfaces/ogma-options.interface'; import { LogObject } from './log.interface'; @@ -13,15 +13,17 @@ export interface InterceptorMeta { export interface InterceptorService { getSuccessContext( data: number, - context: ExecutionContext, + context: ArgumentsHost, startTime: number, options: OgmaInterceptorServiceOptions, ): LogObject; getErrorContext( error: Error | HttpException, - context: ExecutionContext, + context: ArgumentsHost, startTime: number, options: OgmaInterceptorServiceOptions, ): LogObject; + + getStartTime(host: ArgumentsHost): number; } diff --git a/packages/nestjs-module/src/interceptor/providers/abstract-interceptor.service.ts b/packages/nestjs-module/src/interceptor/providers/abstract-interceptor.service.ts index c746731e2..f629a31c4 100644 --- a/packages/nestjs-module/src/interceptor/providers/abstract-interceptor.service.ts +++ b/packages/nestjs-module/src/interceptor/providers/abstract-interceptor.service.ts @@ -1,4 +1,4 @@ -import { ExecutionContext, HttpException, Injectable } from '@nestjs/common'; +import { ArgumentsHost, HttpException, Injectable } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; import { style } from '@ogma/styler'; @@ -21,7 +21,7 @@ export abstract class AbstractInterceptorService implements InterceptorService { */ getSuccessContext( data: unknown, - context: ExecutionContext, + context: ArgumentsHost, startTime: number, options: OgmaInterceptorServiceOptions, ): MetaLogObject { @@ -50,7 +50,7 @@ export abstract class AbstractInterceptorService implements InterceptorService { */ getErrorContext( error: Error | HttpException, - context: ExecutionContext, + context: ArgumentsHost, startTime: number, options: OgmaInterceptorServiceOptions, ): MetaLogObject { @@ -68,23 +68,23 @@ export abstract class AbstractInterceptorService implements InterceptorService { /** * A helper method to get the status based on if the request was an error or success - * @param context the execution context + * @param _context the execution context * @param inColor if the status should be in color * @param error if it was an error * @returns a string representing the status */ - getStatus(_context: ExecutionContext, inColor: boolean, error?: HttpException | Error): string { + getStatus(_context: ArgumentsHost, inColor: boolean, error?: HttpException | Error): string { const status = error ? 500 : 200; return inColor ? this.wrapInColor(status) : status.toString(); } /** * A helper method to allow devs the ability to pass in extra metadata when it comes to the interceptor - * @param context The ExecutionContext - * @param data the response body or the error being returned + * @param _context The ArgumentsHost + * @param _data the response body or the error being returned * @returns whatever metadata you want to add in on a second log line. This can be a string, an object, anything */ - getMeta(_context: ExecutionContext, _data: unknown): unknown { + getMeta(_context: ArgumentsHost, _data: unknown): unknown { return; } @@ -92,7 +92,7 @@ export abstract class AbstractInterceptorService implements InterceptorService { * A helper method to get the Ip of the calling client * @param context the execution context */ - abstract getCallerIp(context: ExecutionContext): string[] | string; + abstract getCallerIp(context: ArgumentsHost): string[] | string; /** * A helper method to get the method type of the request @@ -107,7 +107,7 @@ export abstract class AbstractInterceptorService implements InterceptorService { * * @param context the execution context */ - abstract getMethod(context: ExecutionContext): string; + abstract getMethod(context: ArgumentsHost): string; private getResponseTime(startTime: number): number { return Date.now() - startTime; @@ -117,7 +117,7 @@ export abstract class AbstractInterceptorService implements InterceptorService { * A helper method to get the protocol of the request * @param context execution context from Nest */ - abstract getProtocol(context: ExecutionContext): string; + abstract getProtocol(context: ArgumentsHost): string; /** * A helper method to get what was called @@ -131,14 +131,14 @@ export abstract class AbstractInterceptorService implements InterceptorService { * WebSockets: Subscription Event name * @param context execution context from Nest */ - abstract getCallPoint(context: ExecutionContext): string; + abstract getCallPoint(context: ArgumentsHost): string; /** * A helper method for setting the correlationId to later be retrieved when logging * @param context the execution context * @param requestId the correlationId to set */ - abstract setRequestId(context: ExecutionContext, requestId: string): void; + abstract setRequestId(context: ArgumentsHost, requestId: string): void; protected wrapInColor(status: number): string { let statusString: string; @@ -159,4 +159,8 @@ export abstract class AbstractInterceptorService implements InterceptorService { protected isBetween(comparator: number, bottom: number, top: number): boolean { return comparator >= bottom && comparator < top; } + + getStartTime(_host: ArgumentsHost): number { + return Date.now(); + } } diff --git a/packages/nestjs-module/src/interceptor/providers/delegator.service.ts b/packages/nestjs-module/src/interceptor/providers/delegator.service.ts index 333d16d47..a8e52cff1 100644 --- a/packages/nestjs-module/src/interceptor/providers/delegator.service.ts +++ b/packages/nestjs-module/src/interceptor/providers/delegator.service.ts @@ -1,4 +1,4 @@ -import { ContextType, ExecutionContext, Injectable } from '@nestjs/common'; +import { ArgumentsHost, ContextType, Injectable } from '@nestjs/common'; import { OgmaInterceptorServiceOptions } from '../../interfaces'; import { DelegatorContextReturn, LogObject, MetaLogObject } from '../interfaces/log.interface'; @@ -18,14 +18,19 @@ export class DelegatorService { private readonly gqlParser: GqlInterceptorService, ) {} - setRequestId(context: ExecutionContext, requestId: string): void { + setRequestId(context: ArgumentsHost, requestId: string): void { const parser: Parser = this.getParser(context.getType()); this[parser].setRequestId(context, requestId); } + getRequestId(context: ArgumentsHost): any { + const parser = this.getParser(context.getType()); + return this[parser].getRequestId(context); + } + getContextSuccessString( data: any, - context: ExecutionContext, + context: ArgumentsHost, startTime: number, options: OgmaInterceptorServiceOptions, ): DelegatorContextReturn { @@ -62,7 +67,7 @@ export class DelegatorService { getContextErrorString( error: any, - context: ExecutionContext, + context: ArgumentsHost, startTime: number, options: OgmaInterceptorServiceOptions, ): DelegatorContextReturn { @@ -88,7 +93,7 @@ export class DelegatorService { }: { method: 'getErrorContext' | 'getSuccessContext'; data: any; - context: ExecutionContext; + context: ArgumentsHost; startTime: number; options: OgmaInterceptorServiceOptions; parser: Parser; @@ -101,4 +106,9 @@ export class DelegatorService { ? data : `${data.callerAddress} - ${data.method} ${data.callPoint} ${data.protocol} ${data.status} ${data.responseTime}ms - ${data.contentLength}`; } + + getStartTime(host: ArgumentsHost): number { + const parser = this.getParser(host.getType()); + return this[parser].getStartTime(host); + } } diff --git a/packages/nestjs-module/src/interceptor/providers/gql-interceptor.service.ts b/packages/nestjs-module/src/interceptor/providers/gql-interceptor.service.ts index 8e48559e5..e1f4859a3 100644 --- a/packages/nestjs-module/src/interceptor/providers/gql-interceptor.service.ts +++ b/packages/nestjs-module/src/interceptor/providers/gql-interceptor.service.ts @@ -1,4 +1,4 @@ -import { ExecutionContext, Injectable } from '@nestjs/common'; +import { ArgumentsHost, Injectable } from '@nestjs/common'; import { AbstractInterceptorService } from './abstract-interceptor.service'; @@ -13,15 +13,15 @@ export abstract class GqlInterceptorService extends AbstractInterceptorService { * * this method _should_ look something like this * ```ts - * getContext(context: ExecutionContext) { - * const gql = GqlExecutionContext.create(context); + * getContext(context: ArgumentsHost) { + * const gql = GqlArgumentsHost.create(context); * return gql.getContext(); * } * ``` * @param context execution context from Nest */ - protected abstract getContext(context: ExecutionContext): any; - setRequestId(context: ExecutionContext, requestId: string) { + protected abstract getContext(context: ArgumentsHost): any; + setRequestId(context: ArgumentsHost, requestId: string) { const ctx = this.getContext(context).context; if (ctx[this.reqName]) { ctx[this.reqName].requestId = requestId; @@ -29,4 +29,9 @@ export abstract class GqlInterceptorService extends AbstractInterceptorService { ctx.requestId = requestId; } } + + getRequestId(context: ArgumentsHost): any { + const ctx = this.getContext(context).context; + return ctx[this.reqName]?.requestId ?? ctx.requestId; + } } diff --git a/packages/nestjs-module/src/interceptor/providers/http-interceptor.service.ts b/packages/nestjs-module/src/interceptor/providers/http-interceptor.service.ts index 1c93a5ae8..c635d67f4 100644 --- a/packages/nestjs-module/src/interceptor/providers/http-interceptor.service.ts +++ b/packages/nestjs-module/src/interceptor/providers/http-interceptor.service.ts @@ -1,4 +1,4 @@ -import { ExecutionContext, HttpException, Injectable } from '@nestjs/common'; +import { ArgumentsHost, ExecutionContext, HttpException, Injectable } from '@nestjs/common'; import { HTTP_CODE_METADATA } from '@nestjs/common/constants'; import { AbstractInterceptorService } from './abstract-interceptor.service'; @@ -9,9 +9,10 @@ export abstract class HttpInterceptorService extends AbstractInterceptorService let status: number; const res = this.getResponse(context); status = res.statusCode; - const reflectStatus = this.reflector.get(HTTP_CODE_METADATA, context.getHandler()); - status = reflectStatus || status; - if (error) { + if (!error) { + const reflectStatus = this.reflector.get(HTTP_CODE_METADATA, context.getHandler()); + status = reflectStatus || status; + } else { status = this.determineStatusCodeFromError(error); } return inColor ? this.wrapInColor(status) : status.toString(); @@ -32,7 +33,7 @@ export abstract class HttpInterceptorService extends AbstractInterceptorService * @param context execution context from Nest * @returns the adapter's response object */ - getResponse(context: ExecutionContext) { + getResponse(context: ArgumentsHost) { return context.switchToHttp().getResponse(); } @@ -41,7 +42,16 @@ export abstract class HttpInterceptorService extends AbstractInterceptorService * @param context execution context from Nest * @returns the adapter's request object */ - getRequest(context: ExecutionContext) { + getRequest(context: ArgumentsHost) { return context.switchToHttp().getRequest(); } + + setRequestId(context: ArgumentsHost, requestId: string): void { + const req = this.getRequest(context) as any; + req.requestId = requestId; + } + + getRequestId(context: ArgumentsHost) { + return this.getRequest(context).requestId; + } } diff --git a/packages/nestjs-module/src/interceptor/providers/rpc-interceptor.service.ts b/packages/nestjs-module/src/interceptor/providers/rpc-interceptor.service.ts index e609faa3f..ab9019471 100644 --- a/packages/nestjs-module/src/interceptor/providers/rpc-interceptor.service.ts +++ b/packages/nestjs-module/src/interceptor/providers/rpc-interceptor.service.ts @@ -1,4 +1,4 @@ -import { ExecutionContext, Injectable } from '@nestjs/common'; +import { ArgumentsHost, ExecutionContext, Injectable } from '@nestjs/common'; import { AbstractInterceptorService } from './abstract-interceptor.service'; @@ -13,7 +13,7 @@ export abstract class RpcInterceptorService extends AbstractInterceptorService { * @param context execution context from Nest * @returns The data object for the RPC adapter */ - getData(context: ExecutionContext): T { + getData(context: ArgumentsHost): T { return context.switchToRpc().getData(); } @@ -22,7 +22,16 @@ export abstract class RpcInterceptorService extends AbstractInterceptorService { * @param context execution context from Nest * @returns The client object for the RPC adapter */ - getClient(context: ExecutionContext): T { + getClient(context: ArgumentsHost): T { return context.switchToRpc().getContext(); } + + setRequestId(context: ArgumentsHost, requestId: any): void { + const client = this.getClient<{ requestId: any }>(context); + client.requestId = requestId; + } + + getRequestId(context: ArgumentsHost): any { + return this.getClient<{ requestId: any }>(context).requestId; + } } diff --git a/packages/nestjs-module/src/interceptor/providers/websocket-interceptor.service.ts b/packages/nestjs-module/src/interceptor/providers/websocket-interceptor.service.ts index ad3078fa9..c6435e1d4 100644 --- a/packages/nestjs-module/src/interceptor/providers/websocket-interceptor.service.ts +++ b/packages/nestjs-module/src/interceptor/providers/websocket-interceptor.service.ts @@ -1,4 +1,4 @@ -import { ExecutionContext, Injectable } from '@nestjs/common'; +import { ArgumentsHost, ExecutionContext, Injectable } from '@nestjs/common'; import { AbstractInterceptorService } from './abstract-interceptor.service'; @@ -13,7 +13,16 @@ export abstract class WebsocketInterceptorService extends AbstractInterceptorSer * @param context execution context from Nest * @returns the client object for the websocket adapter */ - getClient(context: ExecutionContext) { + getClient(context: ArgumentsHost) { return context.switchToWs().getClient(); } + + setRequestId(context: ArgumentsHost, requestId: any) { + const client = this.getClient(context); + client.requestId = requestId; + } + + getRequestId(context: ArgumentsHost): any { + return this.getClient(context).requestId; + } } diff --git a/packages/nestjs-module/src/ogma-core.module.ts b/packages/nestjs-module/src/ogma-core.module.ts index 5cef65981..c341f7987 100644 --- a/packages/nestjs-module/src/ogma-core.module.ts +++ b/packages/nestjs-module/src/ogma-core.module.ts @@ -1,5 +1,6 @@ import { Global, Module } from '@nestjs/common'; +import { OgmaFilterLogger } from './filter/ogma-filter.logger'; import { DelegatorService, GqlInterceptorService, @@ -71,6 +72,7 @@ import { ConfigurableModuleClass } from './ogma-core.module-definition'; }, OgmaService, DelegatorService, + OgmaFilterLogger, ], exports: [ OGMA_INSTANCE, @@ -81,6 +83,7 @@ import { ConfigurableModuleClass } from './ogma-core.module-definition'; GqlInterceptorService, RpcInterceptorService, WebsocketInterceptorService, + OgmaFilterLogger, ], }) export class OgmaCoreModule extends ConfigurableModuleClass {} diff --git a/packages/platform-express/src/express-interceptor.service.ts b/packages/platform-express/src/express-interceptor.service.ts index a627f7712..3764e5e67 100644 --- a/packages/platform-express/src/express-interceptor.service.ts +++ b/packages/platform-express/src/express-interceptor.service.ts @@ -25,11 +25,6 @@ export class ExpressParser extends HttpInterceptorService { return `HTTP/${this.getHttpMajor(req)}.${this.getHttpMinor(req)}`; } - setRequestId(context: ExecutionContext, requestId: string): void { - const req = this.getRequest(context) as any; - req.requestId = requestId; - } - private getHttpMajor(req: Request): number { return req.httpVersionMajor; } diff --git a/packages/platform-fastify/src/fastify-interceptor.service.ts b/packages/platform-fastify/src/fastify-interceptor.service.ts index 03bb41600..a72eca926 100644 --- a/packages/platform-fastify/src/fastify-interceptor.service.ts +++ b/packages/platform-fastify/src/fastify-interceptor.service.ts @@ -19,11 +19,6 @@ export class FastifyParser extends HttpInterceptorService { return req.raw.method || 'GET'; } - setRequestId(context: ExecutionContext, requestId: string) { - const req = this.getRequest(context) as any; - req.requestId = requestId; - } - getProtocol(context: ExecutionContext): string { const req = this.getRequest(context); return `HTTP/${req.raw.httpVersionMajor}.${req.raw.httpVersionMinor}`; diff --git a/packages/platform-grpc/src/grpc-interceptor.service.ts b/packages/platform-grpc/src/grpc-interceptor.service.ts index ca1976d7b..55b2b6f11 100644 --- a/packages/platform-grpc/src/grpc-interceptor.service.ts +++ b/packages/platform-grpc/src/grpc-interceptor.service.ts @@ -19,9 +19,4 @@ export class GrpcParser extends RpcInterceptorService { getMethod() { return 'gRPC'; } - - setRequestId(context: ExecutionContext, requestId: string): void { - const grpcContext = this.getClient<{ requestId: string }>(context); - grpcContext.requestId = requestId; - } } diff --git a/packages/platform-kafka/src/kafka-interceptor.service.ts b/packages/platform-kafka/src/kafka-interceptor.service.ts index 0549d27c3..bcd408d2e 100644 --- a/packages/platform-kafka/src/kafka-interceptor.service.ts +++ b/packages/platform-kafka/src/kafka-interceptor.service.ts @@ -20,9 +20,4 @@ export class KafkaParser extends RpcInterceptorService { getProtocol() { return 'kafka'; } - - setRequestId(context: ExecutionContext, requestId: string): void { - const client = this.getClient<{ requestId: string }>(context); - client.requestId = requestId; - } } diff --git a/packages/platform-mqtt/src/mqtt-interceptor.service.ts b/packages/platform-mqtt/src/mqtt-interceptor.service.ts index b63c7a30d..5e62ec245 100644 --- a/packages/platform-mqtt/src/mqtt-interceptor.service.ts +++ b/packages/platform-mqtt/src/mqtt-interceptor.service.ts @@ -22,9 +22,4 @@ export class MqttParser extends RpcInterceptorService { getProtocol(): string { return 'mqtt'; } - - setRequestId(context: ExecutionContext, requestId: string): void { - const client = this.getClient(context) as any; - client.requestId = requestId; - } } diff --git a/packages/platform-nats/src/nats-interceptor.service.ts b/packages/platform-nats/src/nats-interceptor.service.ts index 88ae9df4c..e7fd05395 100644 --- a/packages/platform-nats/src/nats-interceptor.service.ts +++ b/packages/platform-nats/src/nats-interceptor.service.ts @@ -21,9 +21,4 @@ export class NatsParser extends RpcInterceptorService { getProtocol() { return 'nats'; } - - setRequestId(context: ExecutionContext, requestId: string): void { - const client = this.getClient(context); - client.requestId = requestId; - } } diff --git a/packages/platform-rabbitmq/src/rabbitmq-interceptor.service.ts b/packages/platform-rabbitmq/src/rabbitmq-interceptor.service.ts index b25627503..26d29105c 100644 --- a/packages/platform-rabbitmq/src/rabbitmq-interceptor.service.ts +++ b/packages/platform-rabbitmq/src/rabbitmq-interceptor.service.ts @@ -20,9 +20,4 @@ export class RabbitMqParser extends RpcInterceptorService { getProtocol() { return 'amqp'; } - - setRequestId(context: ExecutionContext, requestId: string): void { - const client = this.getClient(context); - client.requestId = requestId; - } } diff --git a/packages/platform-redis/src/redis-interceptor.service.ts b/packages/platform-redis/src/redis-interceptor.service.ts index e87caf708..9e4c22c38 100644 --- a/packages/platform-redis/src/redis-interceptor.service.ts +++ b/packages/platform-redis/src/redis-interceptor.service.ts @@ -20,9 +20,4 @@ export class RedisParser extends RpcInterceptorService { getMethod(): string { return 'REDIS'; } - - setRequestId(context: ExecutionContext, requestId: string): void { - const client = this.getClient(context); - client.requestId = requestId; - } } diff --git a/packages/platform-socket.io/src/socket-io-interceptor.service.ts b/packages/platform-socket.io/src/socket-io-interceptor.service.ts index b16ef0de3..37e1d7c3b 100644 --- a/packages/platform-socket.io/src/socket-io-interceptor.service.ts +++ b/packages/platform-socket.io/src/socket-io-interceptor.service.ts @@ -20,9 +20,4 @@ export class SocketIOParser extends WebsocketInterceptorService { getMethod(): string { return 'socket.io'; } - - setRequestId(context: ExecutionContext, requestId: string): void { - const client = this.getClient(context) as any; - client.requestId = requestId; - } } diff --git a/packages/platform-tcp/src/tcp-interceptor.service.ts b/packages/platform-tcp/src/tcp-interceptor.service.ts index 46472503b..42cedca70 100644 --- a/packages/platform-tcp/src/tcp-interceptor.service.ts +++ b/packages/platform-tcp/src/tcp-interceptor.service.ts @@ -23,11 +23,6 @@ export class TcpParser extends RpcInterceptorService { return client.getSocketRef().socket.remoteFamily; } - setRequestId(context: ExecutionContext, requestId: string): void { - const client = this.getClient(context); - client.requestId = requestId; - } - getClient(context: ExecutionContext): T { return super.getClient(context); } diff --git a/packages/platform-ws/src/ws-interceptor.service.ts b/packages/platform-ws/src/ws-interceptor.service.ts index 3965e42fc..e7ec6cc65 100644 --- a/packages/platform-ws/src/ws-interceptor.service.ts +++ b/packages/platform-ws/src/ws-interceptor.service.ts @@ -14,9 +14,4 @@ export class WsParser extends WebsocketInterceptorService { getMethod(): string { return 'websocket'; } - - setRequestId(context: ExecutionContext, requestId: string): void { - const client = this.getClient(context) as any; - client.requestId = requestId; - } }