fixup logger field and metadata handling
Some checks failed
build / test (push) Failing after 56s
codeql / analyze (go) (push) Failing after 1m50s
build / lint (push) Successful in 9m19s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-03-11 23:52:29 +03:00
parent a3f79a7bed
commit a424fd9722

View File

@ -3,6 +3,7 @@ package requestid
import ( import (
"context" "context"
"net/textproto" "net/textproto"
"strings"
"go.unistack.org/micro/v4/client" "go.unistack.org/micro/v4/client"
"go.unistack.org/micro/v4/logger" "go.unistack.org/micro/v4/logger"
@ -13,9 +14,10 @@ import (
) )
func init() { func init() {
requestIDLog := strings.ToLower(DefaultMetadataKey)
logger.DefaultContextAttrFuncs = append(logger.DefaultContextAttrFuncs, func(ctx context.Context) []interface{} { logger.DefaultContextAttrFuncs = append(logger.DefaultContextAttrFuncs, func(ctx context.Context) []interface{} {
if v, ok := ctx.Value(XRequestIDKey{}).(string); ok { if v, ok := ctx.Value(XRequestIDKey{}).(string); ok {
return []interface{}{DefaultMetadataKey, v} return []interface{}{requestIDLog, v}
} }
return nil return nil
}) })
@ -52,7 +54,7 @@ var DefaultMetadataFunc = func(ctx context.Context) (context.Context, error) {
if !ok { if !ok {
omd = metadata.New(1) omd = metadata.New(1)
omd.Set(DefaultMetadataKey, xid) omd.Set(DefaultMetadataKey, xid)
ctx = metadata.NewOutgoingContext(ctx, imd) ctx = metadata.NewOutgoingContext(ctx, omd)
} else if _, ok = omd.Get(DefaultMetadataKey); !ok { } else if _, ok = omd.Get(DefaultMetadataKey); !ok {
omd.Set(DefaultMetadataKey, xid) omd.Set(DefaultMetadataKey, xid)
} }