feat(logging): add trace ID propagation via AsyncLocalStorage

- add TraceInterceptor that reads x-trace-id header or generates a UUID
- add AsyncLocalStorage store in common/trace-context for request-scoped trace ID
- replace NestJS Logger with TraceLogger (extends ConsoleLogger) that injects trace ID into log context
- register TraceInterceptor globally before LoggingInterceptor
- move HealthController into HealthModule so global interceptors apply to /healthz
- omit body/response from log lines when empty or null
This commit is contained in:
ars9 committed 2026-04-08 12:20:06 +03:00
1 parent 7f5a2bfe18
commit 6fd991811f
12 files changed
+72 -19

No files matched your search

+2 -2
View File
@@ -5,13 +5,13 @@ import {
ExceptionFilter,
HttpException,
InternalServerErrorException,
Logger,
} from '@nestjs/common';
import { TraceLogger } from '../common/trace-logger';
import type { Request, Response } from 'express';
@Catch(BadRequestException, InternalServerErrorException)
export class HttpExceptionFilter implements ExceptionFilter {
private readonly logger = new Logger(HttpExceptionFilter.name);
private readonly logger = new TraceLogger(HttpExceptionFilter.name);
catch(exception: HttpException, host: ArgumentsHost): void {
const ctx = host.switchToHttp();