add request id in context #99

Merged
vtolstov merged 7 commits from rq into v3 2023-08-23 16:31:29 +03:00
Showing only changes of commit d03bf1aa14 - Show all commits

View File

@ -10,6 +10,8 @@ import (
"go.unistack.org/micro/v3/util/id" "go.unistack.org/micro/v3/util/id"
) )
var XRequestIDKey struct{}
// DefaultMetadataKey contains metadata key // DefaultMetadataKey contains metadata key
var DefaultMetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id") var DefaultMetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id")
@ -40,7 +42,8 @@ var DefaultMetadataFunc = func(ctx context.Context) (context.Context, error) {
omd.Set(DefaultMetadataKey, v) omd.Set(DefaultMetadataKey, v)
ctx = metadata.NewIncomingContext(ctx, imd) ctx = metadata.NewIncomingContext(ctx, imd)
ctx = metadata.NewOutgoingContext(ctx, omd) ctx = metadata.NewOutgoingContext(ctx, omd)
return ctx, nil
return context.WithValue(ctx, XRequestIDKey, v), nil
} }
type wrapper struct { type wrapper struct {