diff --git a/go.mod b/go.mod index c176ffc..cde3b2d 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,6 @@ module go.unistack.org/micro-wrapper-requestid/v4 go 1.20 -require go.unistack.org/micro/v4 v4.0.7 +require go.unistack.org/micro/v4 v4.0.14 + +require golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect diff --git a/go.sum b/go.sum index 1b927c8..95c86db 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo= -go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs= -go.unistack.org/micro/v4 v4.0.7 h1:2lwtZlHcSwgkahhFbkI4x1lOS79lw8uLHtcEhlFF+AM= -go.unistack.org/micro/v4 v4.0.7/go.mod h1:bVEYTlPi0EsdgZZt311bIroDg9ict7ky3C87dSCCAGk= +go.unistack.org/micro/v4 v4.0.14 h1:zN+aVfTceei3TPzuA7f2wAXLYHoSHWpx2XgW8yqaTIA= +go.unistack.org/micro/v4 v4.0.14/go.mod h1:ZDgU9931vm2l7X6RN/6UuwRIVp24GRdmQ7dKmegArk4= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= diff --git a/requestid.go b/requestid.go index 5deb5d2..50db766 100644 --- a/requestid.go +++ b/requestid.go @@ -5,12 +5,22 @@ import ( "net/textproto" "go.unistack.org/micro/v4/client" + "go.unistack.org/micro/v4/logger" "go.unistack.org/micro/v4/metadata" "go.unistack.org/micro/v4/options" "go.unistack.org/micro/v4/server" "go.unistack.org/micro/v4/util/id" ) +func init() { + logger.DefaultContextAttrFuncs = append(logger.DefaultContextAttrFuncs, func(ctx context.Context) []interface{} { + if v, ok := ctx.Value(XRequestIDKey).(string); ok { + return []interface{}{DefaultMetadataKey, v} + } + return nil + }) +} + var XRequestIDKey struct{} // DefaultMetadataKey contains metadata key x-request-id