Skip to content

Instantly share code, notes, and snippets.

@sat0yu
Created July 7, 2019 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sat0yu/423e142c8c9367fcffb7b808ae444b17 to your computer and use it in GitHub Desktop.
Save sat0yu/423e142c8c9367fcffb7b808ae444b17 to your computer and use it in GitHub Desktop.
sentry-raven-grpc/interceptor.go
// ErrorCapturer specifies the implementation of a method to capture the given error
type ErrorCapturer interface {
CaptureError(err error, tags map[string]string) string
}
// SentryRavenInterceptor creates an interceptor which catches the errors from each service method and reports them to Sentry
func SentryRavenInterceptor(ec ErrorCapturer) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, _info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
resp, err := handler(ctx, req)
if err != nil {
ec.CaptureError(err, nil)
}
return resp, err
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment