lab6: Collector, Prometheus/Loki/Tempo/Grafana, alerts, incidents, track 1 (cost of observability)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user