Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrGrpcInternalError = grpc.Errorf(codes.Unknown, "internal server error")
ErrGrpcInternalError indicates an internal server error
Functions ¶
func Logger ¶
func Logger(l *logrus.Logger) grpc.UnaryServerInterceptor
Logger returns an interceptor that will set on the context a *logrus.Entry that will automatically be tagged with the request_id UUIDv4.
func Timer ¶
func Timer(m *metrics.Metrics) grpc.UnaryServerInterceptor
Timer is a grpc middleware for handling timing how long endpoints take to handle requests and send them to the client given. Emits 2 metrics to the given statsd client:
* A counter for the endpoint so you can see how many times it has been called * A timer to see how long the endpoint takes.
So given a prefix of "production.myapp", and an RPC endpoint called "CreateThing", you'd have 2 keys emitted to statsd:
* INCR production.myapp.CreateThing * TIMING production.myapp.CreateThing.duration
Types ¶
type ErrorFielder ¶
ErrorFielder declares something that fulfills error interface and has Logrus error fields. We will use this to pass error fields from handlers to middlewares for Logs implements error interface in order to be passed around as an error
type ErrorKeyer ¶
ErrorKeyer declares something that fulfills error interface and has a key. We will use this when we want machine readable error string alongside error message (e.g. proto errors) implements error interface in order to be passed around as an error
type FieldErr ¶
FieldErr implements ErrorFielder
func NewFieldErr ¶
NewFieldErr creates a new error with fields
type Interceptor ¶
type Interceptor struct {
// contains filtered or unexported fields
}
Interceptor makes it easy to return unary interceptors for grpc servers
func (*Interceptor) Middleware ¶
func (i *Interceptor) Middleware() grpc.UnaryServerInterceptor
Middleware returns a grpc.UnaryServerHandler compatible function documented here https://github.com/grpc/grpc-go/tree/master/interceptor.go#L73 It will handle intercepting errors and unwrapping the original error for logging.
A grpc endpoint should return generic errors such as "company not found" by wrapping the original error. This chaining logic shamelessly stolen from https://github.com/mwitkow/go-grpc-middleware/blob/master/chain.go
func (*Interceptor) Use ¶
func (i *Interceptor) Use(m grpc.UnaryServerInterceptor)
Use adds a middleware to the chain for the server interceptor