diff --git a/interceptors.go b/interceptors.go index 1675efb..de22490 100644 --- a/interceptors.go +++ b/interceptors.go @@ -332,7 +332,11 @@ func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientI return grpc_opentracing.UnaryClientInterceptor(options...) } -// HystrixClientInterceptor is the interceptor that intercepts all client requests and adds hystrix info to them +// HystrixClientInterceptor returns a unary client interceptor that executes the RPC inside a Hystrix command. +// +// The interceptor applies provided default and per-call client options to configure Hystrix behavior (for example the command name, disabled flag, excluded errors, and excluded gRPC status codes). +// If Hystrix is disabled via options, the RPC is invoked directly. If the underlying RPC returns an error that matches any configured excluded error or whose gRPC status code matches any configured excluded code, Hystrix fallback is skipped and the RPC error is returned. +// Panics raised during the RPC invocation are captured and reported to the notifier before being converted into an error. If the RPC itself returns an error, that error is returned; otherwise any error produced by Hystrix is returned. func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor { return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { options := clientOptions{ @@ -457,4 +461,4 @@ func TraceIdInterceptor() grpc.UnaryServerInterceptor { } return handler(ctx, req) } -} +} \ No newline at end of file diff --git a/options.go b/options.go index 5688bc1..74bba80 100644 --- a/options.go +++ b/options.go @@ -26,7 +26,8 @@ func (h *optionCarrier) process(co *clientOptions) { h.processor(co) } -// WithHystrixName changes the hystrix name to be used in the client interceptors +// WithHystrixName creates a clientOption that sets the Hystrix command name used by client interceptors. +// If name is empty, the existing Hystrix name is left unchanged. func WithHystrixName(name string) clientOption { return &optionCarrier{ processor: func(co *clientOptions) { @@ -55,7 +56,8 @@ func WithHystrix() clientOption { } } -// WithHystrixExcludedErrors sets the errors that should be excluded from hystrix circuit breaker +// WithHystrixExcludedErrors returns a clientOption that adds the provided errors to the list of errors +// excluded from the Hystrix circuit breaker. func WithHystrixExcludedErrors(errors ...error) clientOption { return &optionCarrier{ processor: func(co *clientOptions) { @@ -64,11 +66,11 @@ func WithHystrixExcludedErrors(errors ...error) clientOption { } } -// WithHystrixExcludedCodes sets the gRPC codes that should be excluded from hystrix circuit breaker -func WithHystrixExcludedCodes(grpcCodes ...codes.Code) clientOption { +// WithHystrixExcludedCodes returns a clientOption that appends the provided gRPC codes to the list of codes excluded from the Hystrix circuit breaker. +func WithHystrixExcludedCodes(codes ...codes.Code) clientOption { return &optionCarrier{ processor: func(co *clientOptions) { - co.excludedCodes = append(co.excludedCodes, grpcCodes...) + co.excludedCodes = append(co.excludedCodes, codes...) }, } }