insert request id in context
Some checks failed
dependabot-automerge / automerge (pull_request) Has been skipped
prbuild / test (pull_request) Failing after 1m29s
prbuild / lint (pull_request) Failing after 2m38s
autoapprove / autoapprove (pull_request) Failing after 1m25s
automerge / automerge (pull_request) Failing after 4s
codeql / analyze (go) (pull_request) Failing after 3m12s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2023-08-23 16:34:04 +03:00
parent a7932622b2
commit 1a3daf4263

View File

@ -10,6 +10,8 @@ import (
"go.unistack.org/micro/v4/util/id" "go.unistack.org/micro/v4/util/id"
) )
var XRequestIDKey struct{}
// DefaultMetadataKey contains metadata key x-request-id // DefaultMetadataKey contains metadata key x-request-id
var DefaultMetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id") var DefaultMetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id")
@ -38,6 +40,7 @@ var DefaultMetadataFunc = func(ctx context.Context) (context.Context, error) {
} }
imd.Set(DefaultMetadataKey, v) imd.Set(DefaultMetadataKey, v)
omd.Set(DefaultMetadataKey, v) omd.Set(DefaultMetadataKey, v)
ctx = context.WithValue(ctx, XRequestIDKey, 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 ctx, nil