Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var (
```

<a name="AddStreamClientInterceptor"></a>
## func [AddStreamClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L84>)
## func [AddStreamClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L85>)

```go
func AddStreamClientInterceptor(ctx context.Context, i ...grpc.StreamClientInterceptor)
Expand All @@ -70,7 +70,7 @@ func AddStreamClientInterceptor(ctx context.Context, i ...grpc.StreamClientInter
AddStreamClientInterceptor adds a server interceptor to default server interceptors

<a name="AddStreamServerInterceptor"></a>
## func [AddStreamServerInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L67>)
## func [AddStreamServerInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L68>)

```go
func AddStreamServerInterceptor(ctx context.Context, i ...grpc.StreamServerInterceptor)
Expand All @@ -79,7 +79,7 @@ func AddStreamServerInterceptor(ctx context.Context, i ...grpc.StreamServerInter
AddStreamServerInterceptor adds a server interceptor to default server interceptors

<a name="AddUnaryClientInterceptor"></a>
## func [AddUnaryClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L79>)
## func [AddUnaryClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L80>)

```go
func AddUnaryClientInterceptor(ctx context.Context, i ...grpc.UnaryClientInterceptor)
Expand All @@ -88,7 +88,7 @@ func AddUnaryClientInterceptor(ctx context.Context, i ...grpc.UnaryClientInterce
AddUnaryClientInterceptor adds a server interceptor to default server interceptors

<a name="AddUnaryServerInterceptor"></a>
## func [AddUnaryServerInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L62>)
## func [AddUnaryServerInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L63>)

```go
func AddUnaryServerInterceptor(ctx context.Context, i ...grpc.UnaryServerInterceptor)
Expand All @@ -97,7 +97,7 @@ func AddUnaryServerInterceptor(ctx context.Context, i ...grpc.UnaryServerInterce
AddUnaryServerInterceptor adds a server interceptor to default server interceptors

<a name="DebugLoggingInterceptor"></a>
## func [DebugLoggingInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L231>)
## func [DebugLoggingInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L232>)

```go
func DebugLoggingInterceptor() grpc.UnaryServerInterceptor
Expand All @@ -106,7 +106,7 @@ func DebugLoggingInterceptor() grpc.UnaryServerInterceptor
DebugLoggingInterceptor is the interceptor that logs all request/response from a handler

<a name="DefaultClientInterceptor"></a>
## func [DefaultClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L221>)
## func [DefaultClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L222>)

```go
func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptor
Expand All @@ -115,7 +115,7 @@ func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterc
DefaultClientInterceptor are the set of default interceptors that should be applied to all client calls

<a name="DefaultClientInterceptors"></a>
## func [DefaultClientInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L147>)
## func [DefaultClientInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L148>)

```go
func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor
Expand All @@ -124,7 +124,7 @@ func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInt
DefaultClientInterceptors are the set of default interceptors that should be applied to all client calls

<a name="DefaultClientStreamInterceptor"></a>
## func [DefaultClientStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L226>)
## func [DefaultClientStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L227>)

```go
func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClientInterceptor
Expand All @@ -133,7 +133,7 @@ func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClien
DefaultClientStreamInterceptor are the set of default interceptors that should be applied to all stream client calls

<a name="DefaultClientStreamInterceptors"></a>
## func [DefaultClientStreamInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L178>)
## func [DefaultClientStreamInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L179>)

```go
func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamClientInterceptor
Expand All @@ -142,7 +142,7 @@ func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamCl
DefaultClientStreamInterceptors are the set of default interceptors that should be applied to all stream client calls

<a name="DefaultInterceptors"></a>
## func [DefaultInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L126>)
## func [DefaultInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L127>)

```go
func DefaultInterceptors() []grpc.UnaryServerInterceptor
Expand All @@ -151,7 +151,7 @@ func DefaultInterceptors() []grpc.UnaryServerInterceptor
DefaultInterceptors are the set of default interceptors that are applied to all coldbrew methods

<a name="DefaultStreamInterceptors"></a>
## func [DefaultStreamInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L203>)
## func [DefaultStreamInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L204>)

```go
func DefaultStreamInterceptors() []grpc.StreamServerInterceptor
Expand All @@ -160,7 +160,7 @@ func DefaultStreamInterceptors() []grpc.StreamServerInterceptor
DefaultStreamInterceptors are the set of default interceptors that should be applied to all coldbrew streams

<a name="DoHTTPtoGRPC"></a>
## func [DoHTTPtoGRPC](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L112>)
## func [DoHTTPtoGRPC](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L113>)

```go
func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error)
Expand All @@ -186,7 +186,7 @@ func (s *svc) echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResp
```

<a name="FilterMethodsFunc"></a>
## func [FilterMethodsFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L45>)
## func [FilterMethodsFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L46>)

```go
func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool
Expand All @@ -195,7 +195,7 @@ func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool
FilterMethodsFunc is the default implementation of Filter function

<a name="GRPCClientInterceptor"></a>
## func [GRPCClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L330>)
## func [GRPCClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L331>)

```go
func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientInterceptor
Expand All @@ -204,7 +204,7 @@ func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientI
GRPCClientInterceptor is the interceptor that intercepts all cleint requests and adds tracing info to them

<a name="HystrixClientInterceptor"></a>
## func [HystrixClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L335>)
## func [HystrixClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L336>)

```go
func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor
Expand All @@ -213,7 +213,7 @@ func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientIn
HystrixClientInterceptor is the interceptor that intercepts all client requests and adds hystrix info to them

<a name="NRHttpTracer"></a>
## func [NRHttpTracer](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L418>)
## func [NRHttpTracer](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L427>)

```go
func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)
Expand All @@ -222,7 +222,7 @@ func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)
NRHttpTracer adds newrelic tracing to this http function

<a name="NewRelicClientInterceptor"></a>
## func [NewRelicClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L319>)
## func [NewRelicClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L320>)

```go
func NewRelicClientInterceptor() grpc.UnaryClientInterceptor
Expand All @@ -231,7 +231,7 @@ func NewRelicClientInterceptor() grpc.UnaryClientInterceptor
NewRelicClientInterceptor intercepts all client actions and reports them to newrelic

<a name="NewRelicInterceptor"></a>
## func [NewRelicInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L266>)
## func [NewRelicInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L267>)

```go
func NewRelicInterceptor() grpc.UnaryServerInterceptor
Expand All @@ -240,7 +240,7 @@ func NewRelicInterceptor() grpc.UnaryServerInterceptor
NewRelicInterceptor intercepts all server actions and reports them to newrelic

<a name="OptionsInterceptor"></a>
## func [OptionsInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L257>)
## func [OptionsInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L258>)

```go
func OptionsInterceptor() grpc.UnaryServerInterceptor
Expand All @@ -249,7 +249,7 @@ func OptionsInterceptor() grpc.UnaryServerInterceptor


<a name="PanicRecoveryInterceptor"></a>
## func [PanicRecoveryInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L297>)
## func [PanicRecoveryInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L298>)

```go
func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor
Expand All @@ -258,7 +258,7 @@ func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor


<a name="ResponseTimeLoggingInterceptor"></a>
## func [ResponseTimeLoggingInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L241>)
## func [ResponseTimeLoggingInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L242>)

```go
func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor
Expand All @@ -267,7 +267,7 @@ func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor
ResponseTimeLoggingInterceptor logs response time for each request on server

<a name="ResponseTimeLoggingStreamInterceptor"></a>
## func [ResponseTimeLoggingStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L386>)
## func [ResponseTimeLoggingStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L395>)

```go
func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor
Expand All @@ -276,7 +276,7 @@ func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor
ResponseTimeLoggingStreamInterceptor logs response time for stream RPCs.

<a name="ServerErrorInterceptor"></a>
## func [ServerErrorInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L278>)
## func [ServerErrorInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L279>)

```go
func ServerErrorInterceptor() grpc.UnaryServerInterceptor
Expand All @@ -285,7 +285,7 @@ func ServerErrorInterceptor() grpc.UnaryServerInterceptor
ServerErrorInterceptor intercepts all server actions and reports them to error notifier

<a name="ServerErrorStreamInterceptor"></a>
## func [ServerErrorStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L398>)
## func [ServerErrorStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L407>)

```go
func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor
Expand All @@ -294,7 +294,7 @@ func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor
ServerErrorStreamInterceptor intercepts server errors for stream RPCs and reports them to the error notifier.

<a name="SetFilterFunc"></a>
## func [SetFilterFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L55>)
## func [SetFilterFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L56>)

```go
func SetFilterFunc(ctx context.Context, ff FilterFunc)
Expand All @@ -303,7 +303,7 @@ func SetFilterFunc(ctx context.Context, ff FilterFunc)
SetFilterFunc sets the default filter function to be used by interceptors

<a name="TraceIdInterceptor"></a>
## func [TraceIdInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L440>)
## func [TraceIdInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L449>)

```go
func TraceIdInterceptor() grpc.UnaryServerInterceptor
Expand All @@ -312,7 +312,7 @@ func TraceIdInterceptor() grpc.UnaryServerInterceptor
TraceIdInterceptor allows injecting trace id from request objects

<a name="UseColdBrewClientInterceptors"></a>
## func [UseColdBrewClientInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L91>)
## func [UseColdBrewClientInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L92>)

```go
func UseColdBrewClientInterceptors(ctx context.Context, flag bool)
Expand All @@ -323,7 +323,7 @@ UseColdBrewClientInterceptors allows enabling/disabling coldbrew client intercep
when set to false, the coldbrew client interceptors will not be used

<a name="UseColdBrewServerInterceptors"></a>
## func [UseColdBrewServerInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L74>)
## func [UseColdBrewServerInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L75>)

```go
func UseColdBrewServerInterceptors(ctx context.Context, flag bool)
Expand All @@ -334,7 +334,7 @@ UseColdBrewServerInterceptors allows enabling/disabling coldbrew server intercep
when set to false, the coldbrew server interceptors will not be used

<a name="FilterFunc"></a>
## type [FilterFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L42>)
## type [FilterFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L43>)

If it returns false, the given request will not be traced.

Expand Down
8 changes: 8 additions & 0 deletions interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/newrelic/go-agent/v3/integrations/nrgrpc"
newrelic "github.com/newrelic/go-agent/v3/newrelic"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
)

var (
Expand Down Expand Up @@ -373,6 +374,13 @@ func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientIn
return nil
}
}
if st, ok := status.FromError(invokerErr); ok {
for _, code := range options.excludedCodes {
if st.Code() == code {
return nil
}
}
}
return invokerErr
}, nil)
if invokerErr != nil {
Expand Down
17 changes: 15 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package interceptors

import "google.golang.org/grpc"
import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)

type clientOption interface {
grpc.CallOption
Expand All @@ -11,6 +14,7 @@ type clientOptions struct {
hystrixName string
disableHystrix bool
excludedErrors []error
excludedCodes []codes.Code
}

type optionCarrier struct {
Expand All @@ -22,7 +26,7 @@ func (h *optionCarrier) process(co *clientOptions) {
h.processor(co)
}

//WithHystrixName changes the hystrix name to be used in the client interceptors
// WithHystrixName changes the hystrix name to be used in the client interceptors
func WithHystrixName(name string) clientOption {
return &optionCarrier{
processor: func(co *clientOptions) {
Expand Down Expand Up @@ -59,3 +63,12 @@ func WithHystrixExcludedErrors(errors ...error) clientOption {
},
}
}

// WithHystrixExcludedCodes sets the gRPC codes that should be excluded from hystrix circuit breaker
func WithHystrixExcludedCodes(grpcCodes ...codes.Code) clientOption {
return &optionCarrier{
processor: func(co *clientOptions) {
co.excludedCodes = append(co.excludedCodes, grpcCodes...)
},
}
}