From a424fd9722551e2a24db4894d9eb126c354ad649 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 11 Mar 2024 23:52:29 +0300 Subject: [PATCH] fixup logger field and metadata handling Signed-off-by: Vasiliy Tolstov --- requestid.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/requestid.go b/requestid.go index a9d2ec2..b6fdfb8 100644 --- a/requestid.go +++ b/requestid.go @@ -3,6 +3,7 @@ package requestid import ( "context" "net/textproto" + "strings" "go.unistack.org/micro/v4/client" "go.unistack.org/micro/v4/logger" @@ -13,9 +14,10 @@ import ( ) func init() { + requestIDLog := strings.ToLower(DefaultMetadataKey) logger.DefaultContextAttrFuncs = append(logger.DefaultContextAttrFuncs, func(ctx context.Context) []interface{} { if v, ok := ctx.Value(XRequestIDKey{}).(string); ok { - return []interface{}{DefaultMetadataKey, v} + return []interface{}{requestIDLog, v} } return nil }) @@ -52,7 +54,7 @@ var DefaultMetadataFunc = func(ctx context.Context) (context.Context, error) { if !ok { omd = metadata.New(1) omd.Set(DefaultMetadataKey, xid) - ctx = metadata.NewOutgoingContext(ctx, imd) + ctx = metadata.NewOutgoingContext(ctx, omd) } else if _, ok = omd.Get(DefaultMetadataKey); !ok { omd.Set(DefaultMetadataKey, xid) }