From ad1624e37e9bb18e4497ff436ee45631b15675b3 Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Sat, 17 Aug 2024 20:52:29 +0200 Subject: [PATCH] fix: replace trace-id by trace_id spec: https://opentelemetry.io/docs/specs/otel/compatibility/logging_trace_context --- README.md | 4 ++-- middleware.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6cfdae8..61ac5e3 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,8 @@ Attributes will be injected in log payload. Other global parameters: ```go -sloggin.TraceIDKey = "trace-id" -sloggin.SpanIDKey = "span-id" +sloggin.TraceIDKey = "trace_id" +sloggin.SpanIDKey = "span_id" sloggin.RequestBodyMaxSize = 64 * 1024 // 64KB sloggin.ResponseBodyMaxSize = 64 * 1024 // 64KB sloggin.HiddenRequestHeaders = map[string]struct{}{ ... } diff --git a/middleware.go b/middleware.go index 5ba9cc7..6e28f3b 100644 --- a/middleware.go +++ b/middleware.go @@ -18,8 +18,8 @@ const ( ) var ( - TraceIDKey = "trace-id" - SpanIDKey = "span-id" + TraceIDKey = "trace_id" + SpanIDKey = "span_id" RequestIDKey = "id" RequestBodyMaxSize = 64 * 1024 // 64KB @@ -258,7 +258,7 @@ func NewWithConfig(logger *slog.Logger, config Config) gin.HandlerFunc { } } -// GetRequestID returns the request identifier +// GetRequestID returns the request identifier. func GetRequestID(c *gin.Context) string { requestID, ok := c.Get(requestIDCtx) if !ok { @@ -272,6 +272,7 @@ func GetRequestID(c *gin.Context) string { return "" } +// AddCustomAttributes adds custom attributes to the request context. func AddCustomAttributes(c *gin.Context, attr slog.Attr) { v, exists := c.Get(customAttributesCtxKey) if !exists {