gRPC unary interceptor for auth and timing logs

11415
0

Interceptors are the cleanest way to standardize cross-cutting behavior in gRPC. I use a unary interceptor to extract authorization from metadata, validate it, attach the principal to context.Context, and log the method name and duration. This keeps service methods focused: they read principal from context and do work. The subtle benefit is that all endpoints share the same auth policy and logging format, so your logs are consistent and greppable. I also keep the error surface tight: unauthenticated requests return codes.Unauthenticated and we don't leak whether the token was missing vs invalid. Combined with metrics and tracing interceptors, this becomes a strong baseline for production-grade gRPC services.