diff options
Diffstat (limited to 'internal/tagging')
-rw-r--r-- | internal/tagging/tagging.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/tagging/tagging.go b/internal/tagging/tagging.go new file mode 100644 index 0000000..8e8efe9 --- /dev/null +++ b/internal/tagging/tagging.go @@ -0,0 +1,23 @@ +package tagging + +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 UnaryInterceptor(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) +} |