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:
1 parent
7f5a2bfe18
commit
6fd991811f
12 files changed
+72
-19
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import { ConsoleLogger } from '@nestjs/common';
|
||||
import { getTraceId } from './trace-context';
|
||||
|
||||
export class TraceLogger extends ConsoleLogger {
|
||||
protected override formatContext(context: string): string {
|
||||
const traceId = getTraceId();
|
||||
const traced = traceId ? `${context}:${traceId}` : context;
|
||||
return super.formatContext(traced);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user