blob: 8e8efe902691f8cfdf23214c38a0e2c4c589f712 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)
}
|