feat(server): enable cls plugin to store request id (#9758)

POC
This commit is contained in:
fengmk2
2025-01-20 10:00:21 +00:00
parent fa5e6e1f45
commit 2ae05c28b7
7 changed files with 70 additions and 4 deletions

View File

@@ -1,3 +1,5 @@
import { randomUUID } from 'node:crypto';
import {
DynamicModule,
ForwardReference,
@@ -6,6 +8,7 @@ import {
} from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';
import { get } from 'lodash-es';
import { ClsModule } from 'nestjs-cls';
import { AppController } from './app.controller';
import { getOptionalModuleMetadata } from './base';
@@ -42,6 +45,17 @@ import { REGISTERED_PLUGINS } from './plugins';
import { ENABLED_PLUGINS } from './plugins/registry';
export const FunctionalityModules = [
ClsModule.forRoot({
global: true,
middleware: {
mount: true,
generateId: true,
idGenerator() {
// make every request has a unique id to tracing
return randomUUID();
},
},
}),
ConfigModule.forRoot(),
RuntimeModule,
EventModule,