From f36f77472a82d6ebfac153aed6d17f154ae239a6 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sat, 22 Feb 2025 09:59:10 -0500 Subject: Good foundations --- internal/intercept/tagging.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 internal/intercept/tagging.go (limited to 'internal/intercept') diff --git a/internal/intercept/tagging.go b/internal/intercept/tagging.go new file mode 100644 index 0000000..6479206 --- /dev/null +++ b/internal/intercept/tagging.go @@ -0,0 +1,23 @@ +package intercept + +import ( + "context" + "log/slog" + + "github.com/ChausseBenjamin/rafta/internal/logging" + "github.com/ChausseBenjamin/rafta/internal/util" + "github.com/hashicorp/go-uuid" + "google.golang.org/grpc" +) + +// gRPC interceptor to tag requests with a unique identifier +func Tagging(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { + id, err := uuid.GenerateUUID() + if err != nil { + slog.Error("Unable to generate UUID for request", logging.ErrKey, err) + } + ctx = context.WithValue(ctx, util.ReqIDKey, id) + slog.DebugContext(ctx, "Tagging request with UUID", "value", id) + + return handler(ctx, req) +} -- cgit v1.2.3