diff --git a/requestid/interceptor.go b/requestid/interceptor.go index 395ce23b..bb389eab 100644 --- a/requestid/interceptor.go +++ b/requestid/interceptor.go @@ -28,6 +28,8 @@ func UnaryServerInterceptor() grpc.UnaryServerInterceptor { }() reqID := handleRequestID(ctx) + // add request id to logger + addRequestIDToLogger(ctx, reqID) ctx = NewContext(ctx, reqID) diff --git a/requestid/requestid.go b/requestid/requestid.go index e577ef4f..9fec8d47 100644 --- a/requestid/requestid.go +++ b/requestid/requestid.go @@ -4,7 +4,9 @@ import ( "context" "github.com/google/uuid" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "github.com/infobloxopen/atlas-app-toolkit/gateway" + "github.com/sirupsen/logrus" "google.golang.org/grpc/metadata" ) @@ -41,3 +43,7 @@ func NewContext(ctx context.Context, reqID string) context.Context { md := metadata.Pairs(DefaultRequestIDKey, reqID) return metadata.NewOutgoingContext(ctx, md) } + +func addRequestIDToLogger(ctx context.Context, reqID string) { + ctxlogrus.AddFields(ctx, logrus.Fields{DefaultRequestIDKey: reqID}) +}