fixup logger field and metadata handling
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
c4b4fc187e
commit
25efb945dc
@ -3,6 +3,7 @@ package requestid // import "go.unistack.org/micro-wrapper-requestid/v3"
|
||||
import (
|
||||
"context"
|
||||
"net/textproto"
|
||||
"strings"
|
||||
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
@ -12,9 +13,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
|
||||
})
|
||||
@ -51,7 +53,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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user