Add observabilitty and monitoring

This commit is contained in:
2026-03-03 06:39:42 +00:00
parent 2edb290563
commit b56c78fa07
15 changed files with 1549 additions and 38 deletions

View File

@@ -4,6 +4,8 @@ import (
"context"
"log/slog"
"os"
"go.opentelemetry.io/otel/trace"
)
type contextKey string
@@ -57,3 +59,15 @@ func FromContext(ctx context.Context) string {
}
return ""
}
// LogAttrsWithTrace adds trace context to log attributes for correlation.
func LogAttrsWithTrace(ctx context.Context, attrs ...any) []any {
spanCtx := trace.SpanFromContext(ctx).SpanContext()
if spanCtx.IsValid() {
attrs = append(attrs,
slog.String("trace_id", spanCtx.TraceID().String()),
slog.String("span_id", spanCtx.SpanID().String()),
)
}
return attrs
}