lab6: Collector, Prometheus/Loki/Tempo/Grafana, alerts, incidents, track 1 (cost of observability)

This commit is contained in:
lab6
2026-11-10 01:57:47 +03:00
parent 63dba7627c
commit d558148d0d
142 changed files with 94773 additions and 88 deletions
+10 -3
View File
@@ -1,5 +1,5 @@
import type { LoggerService, LogLevel } from '@nestjs/common';
import { context, trace } from '@opentelemetry/api';
import { context, trace, TraceFlags } from '@opentelemetry/api';
import {
logs,
SeverityNumber,
@@ -166,9 +166,15 @@ export class StructuredLogger implements LoggerService {
const identity = serviceIdentity();
const active = context.active();
const spanContext = trace.getSpan(active)?.spanContext();
let ids: { trace_id: string; span_id: string } | undefined;
let ids:
| { trace_id: string; span_id: string; trace_sampled: boolean }
| undefined;
if (spanContext && trace.isSpanContextValid(spanContext))
ids = { trace_id: spanContext.traceId, span_id: spanContext.spanId };
ids = {
trace_id: spanContext.traceId,
span_id: spanContext.spanId,
trace_sampled: (spanContext.traceFlags & TraceFlags.SAMPLED) !== 0,
};
const body = redact(message).slice(0, MAX_TEXT);
const clean: Record<string, string | number | boolean> = {};
@@ -199,6 +205,7 @@ export class StructuredLogger implements LoggerService {
attributes: {
'event.name': event,
...(contextName ? { 'log.context': contextName } : {}),
...(ids ? { trace_sampled: ids.trace_sampled } : {}),
...clean,
} as AnyValueMap,
context: active,