An open API service indexing awesome lists of open source software.

https://github.com/go-coldbrew/interceptors

Chained gRPC interceptors for logging, tracing, Prometheus metrics, circuit breaking, and retries
https://github.com/go-coldbrew/interceptors

coldbrew go golang grpc interceptor interceptors microservice middleware observability opentelemetry prometheus

Last synced: 3 days ago
JSON representation

Chained gRPC interceptors for logging, tracing, Prometheus metrics, circuit breaking, and retries

Awesome Lists containing this project

README

          

[![CI](https://github.com/go-coldbrew/interceptors/actions/workflows/go.yml/badge.svg)](https://github.com/go-coldbrew/interceptors/actions/workflows/go.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-coldbrew/interceptors)](https://goreportcard.com/report/github.com/go-coldbrew/interceptors)
[![GoDoc](https://pkg.go.dev/badge/github.com/go-coldbrew/interceptors.svg)](https://pkg.go.dev/github.com/go-coldbrew/interceptors)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# interceptors

```go
import "github.com/go-coldbrew/interceptors"
```

Package interceptors provides gRPC server and client interceptors for the ColdBrew framework.

Interceptor configuration functions \(AddUnaryServerInterceptor, SetFilterFunc, etc.\) must be called during program initialization, before the gRPC server starts. They are not safe for concurrent use.

## Index

- [Constants](<#constants>)
- [Variables](<#variables>)
- [func AddStreamClientInterceptor\(ctx context.Context, i ...grpc.StreamClientInterceptor\)](<#AddStreamClientInterceptor>)
- [func AddStreamServerInterceptor\(ctx context.Context, i ...grpc.StreamServerInterceptor\)](<#AddStreamServerInterceptor>)
- [func AddUnaryClientInterceptor\(ctx context.Context, i ...grpc.UnaryClientInterceptor\)](<#AddUnaryClientInterceptor>)
- [func AddUnaryServerInterceptor\(ctx context.Context, i ...grpc.UnaryServerInterceptor\)](<#AddUnaryServerInterceptor>)
- [func DebugLoggingInterceptor\(\) grpc.UnaryServerInterceptor](<#DebugLoggingInterceptor>)
- [func DefaultClientInterceptor\(defaultOpts ...interface\{\}\) grpc.UnaryClientInterceptor](<#DefaultClientInterceptor>)
- [func DefaultClientInterceptors\(defaultOpts ...interface\{\}\) \[\]grpc.UnaryClientInterceptor](<#DefaultClientInterceptors>)
- [func DefaultClientStreamInterceptor\(defaultOpts ...interface\{\}\) grpc.StreamClientInterceptor](<#DefaultClientStreamInterceptor>)
- [func DefaultClientStreamInterceptors\(defaultOpts ...interface\{\}\) \[\]grpc.StreamClientInterceptor](<#DefaultClientStreamInterceptors>)
- [func DefaultInterceptors\(\) \[\]grpc.UnaryServerInterceptor](<#DefaultInterceptors>)
- [func DefaultStreamInterceptors\(\) \[\]grpc.StreamServerInterceptor](<#DefaultStreamInterceptors>)
- [func DoHTTPtoGRPC\(ctx context.Context, svr interface\{\}, handler func\(ctx context.Context, req interface\{\}\) \(interface\{\}, error\), in interface\{\}\) \(interface\{\}, error\)](<#DoHTTPtoGRPC>)
- [func FilterMethodsFunc\(ctx context.Context, fullMethodName string\) bool](<#FilterMethodsFunc>)
- [func GRPCClientInterceptor\(options ...interface\{\}\) grpc.UnaryClientInterceptor](<#GRPCClientInterceptor>)
- [func HystrixClientInterceptor\(defaultOpts ...grpc.CallOption\) grpc.UnaryClientInterceptor](<#HystrixClientInterceptor>)
- [func NRHttpTracer\(pattern string, h http.HandlerFunc\) \(string, http.HandlerFunc\)](<#NRHttpTracer>)
- [func NewRelicClientInterceptor\(\) grpc.UnaryClientInterceptor](<#NewRelicClientInterceptor>)
- [func NewRelicInterceptor\(\) grpc.UnaryServerInterceptor](<#NewRelicInterceptor>)
- [func OptionsInterceptor\(\) grpc.UnaryServerInterceptor](<#OptionsInterceptor>)
- [func PanicRecoveryInterceptor\(\) grpc.UnaryServerInterceptor](<#PanicRecoveryInterceptor>)
- [func ResponseTimeLoggingInterceptor\(ff FilterFunc\) grpc.UnaryServerInterceptor](<#ResponseTimeLoggingInterceptor>)
- [func ResponseTimeLoggingStreamInterceptor\(\) grpc.StreamServerInterceptor](<#ResponseTimeLoggingStreamInterceptor>)
- [func ServerErrorInterceptor\(\) grpc.UnaryServerInterceptor](<#ServerErrorInterceptor>)
- [func ServerErrorStreamInterceptor\(\) grpc.StreamServerInterceptor](<#ServerErrorStreamInterceptor>)
- [func SetClientMetricsOptions\(opts ...grpcprom.ClientMetricsOption\)](<#SetClientMetricsOptions>)
- [func SetFilterFunc\(ctx context.Context, ff FilterFunc\)](<#SetFilterFunc>)
- [func SetResponseTimeLogLevel\(ctx context.Context, level loggers.Level\)](<#SetResponseTimeLogLevel>)
- [func SetServerMetricsOptions\(opts ...grpcprom.ServerMetricsOption\)](<#SetServerMetricsOptions>)
- [func TraceIdInterceptor\(\) grpc.UnaryServerInterceptor](<#TraceIdInterceptor>)
- [func UseColdBrewClientInterceptors\(ctx context.Context, flag bool\)](<#UseColdBrewClientInterceptors>)
- [func UseColdBrewServerInterceptors\(ctx context.Context, flag bool\)](<#UseColdBrewServerInterceptors>)
- [type FilterFunc](<#FilterFunc>)

## Constants

SupportPackageIsVersion1 is a compile\-time assertion constant. Downstream packages \(e.g. core\) reference this constant to enforce version compatibility. When interceptors makes a breaking change, export a new constant and remove this one to force coordinated updates.

```go
const SupportPackageIsVersion1 = true
```

## Variables

```go
var (
//FilterMethods is the list of methods that are filtered by default
FilterMethods = []string{"healthcheck", "readycheck", "serverreflectioninfo"}
)
```


## func [AddStreamClientInterceptor]()

```go
func AddStreamClientInterceptor(ctx context.Context, i ...grpc.StreamClientInterceptor)
```

AddStreamClientInterceptor adds a client stream interceptor to default client stream interceptors. Must be called during initialization, before any RPCs are made. Not safe for concurrent use.


## func [AddStreamServerInterceptor]()

```go
func AddStreamServerInterceptor(ctx context.Context, i ...grpc.StreamServerInterceptor)
```

AddStreamServerInterceptor adds a server interceptor to default server interceptors. Must be called during initialization, before the server starts. Not safe for concurrent use.


## func [AddUnaryClientInterceptor]()

```go
func AddUnaryClientInterceptor(ctx context.Context, i ...grpc.UnaryClientInterceptor)
```

AddUnaryClientInterceptor adds a client interceptor to default client interceptors. Must be called during initialization, before any RPCs are made. Not safe for concurrent use.


## func [AddUnaryServerInterceptor]()

```go
func AddUnaryServerInterceptor(ctx context.Context, i ...grpc.UnaryServerInterceptor)
```

AddUnaryServerInterceptor adds a server interceptor to default server interceptors. Must be called during initialization, before the server starts. Not safe for concurrent use.


## func [DebugLoggingInterceptor]()

```go
func DebugLoggingInterceptor() grpc.UnaryServerInterceptor
```

DebugLoggingInterceptor is the interceptor that logs all request/response from a handler


## func [DefaultClientInterceptor]()

```go
func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptor
```

DefaultClientInterceptor are the set of default interceptors that should be applied to all client calls


## func [DefaultClientInterceptors]()

```go
func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor
```

DefaultClientInterceptors are the set of default interceptors that should be applied to all client calls


## func [DefaultClientStreamInterceptor]()

```go
func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClientInterceptor
```

DefaultClientStreamInterceptor are the set of default interceptors that should be applied to all stream client calls


## func [DefaultClientStreamInterceptors]()

```go
func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamClientInterceptor
```

DefaultClientStreamInterceptors are the set of default interceptors that should be applied to all stream client calls


## func [DefaultInterceptors]()

```go
func DefaultInterceptors() []grpc.UnaryServerInterceptor
```

DefaultInterceptors are the set of default interceptors that are applied to all coldbrew methods


## func [DefaultStreamInterceptors]()

```go
func DefaultStreamInterceptors() []grpc.StreamServerInterceptor
```

DefaultStreamInterceptors are the set of default interceptors that should be applied to all coldbrew streams


## func [DoHTTPtoGRPC]()

```go
func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error)
```


## func [FilterMethodsFunc]()

```go
func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool
```

FilterMethodsFunc is the default implementation of Filter function


## func [GRPCClientInterceptor]()

```go
func GRPCClientInterceptor(options ...interface{}) grpc.UnaryClientInterceptor
```

Deprecated: GRPCClientInterceptor is no longer needed. gRPC tracing is now handled by otelgrpc.NewClientHandler stats handler configured at the client level. This function is retained for backwards compatibility but returns a no\-op interceptor.


## func [HystrixClientInterceptor]()

```go
func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor
```

HystrixClientInterceptor returns a unary client interceptor that executes the RPC inside a Hystrix command.

Note: This interceptor wraps github.com/afex/hystrix\-go which has been unmaintained since 2018. Consider migrating to github.com/failsafe\-go/failsafe\-go for circuit breaker functionality.

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 [NRHttpTracer]()

```go
func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)
```

NRHttpTracer adds newrelic tracing to this http function


## func [NewRelicClientInterceptor]()

```go
func NewRelicClientInterceptor() grpc.UnaryClientInterceptor
```

NewRelicClientInterceptor intercepts all client actions and reports them to newrelic


## func [NewRelicInterceptor]()

```go
func NewRelicInterceptor() grpc.UnaryServerInterceptor
```

NewRelicInterceptor intercepts all server actions and reports them to newrelic


## func [OptionsInterceptor]()

```go
func OptionsInterceptor() grpc.UnaryServerInterceptor
```


## func [PanicRecoveryInterceptor]()

```go
func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor
```


## func [ResponseTimeLoggingInterceptor]()

```go
func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor
```

ResponseTimeLoggingInterceptor logs response time for each request on server


## func [ResponseTimeLoggingStreamInterceptor]()

```go
func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor
```

ResponseTimeLoggingStreamInterceptor logs response time for stream RPCs.


## func [ServerErrorInterceptor]()

```go
func ServerErrorInterceptor() grpc.UnaryServerInterceptor
```

ServerErrorInterceptor intercepts all server actions and reports them to error notifier


## func [ServerErrorStreamInterceptor]()

```go
func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor
```

ServerErrorStreamInterceptor intercepts server errors for stream RPCs and reports them to the error notifier.


## func [SetClientMetricsOptions]()

```go
func SetClientMetricsOptions(opts ...grpcprom.ClientMetricsOption)
```

SetClientMetricsOptions appends gRPC client metrics options. Must be called during initialization, before the server starts. Not safe for concurrent use.


## func [SetFilterFunc]()

```go
func SetFilterFunc(ctx context.Context, ff FilterFunc)
```

SetFilterFunc sets the default filter function to be used by interceptors. Must be called during initialization, before the server starts. Not safe for concurrent use.


## func [SetResponseTimeLogLevel]()

```go
func SetResponseTimeLogLevel(ctx context.Context, level loggers.Level)
```

SetResponseTimeLogLevel sets the log level for response time logging. Default is InfoLevel. Must be called during initialization, before the server starts. Not safe for concurrent use.


## func [SetServerMetricsOptions]()

```go
func SetServerMetricsOptions(opts ...grpcprom.ServerMetricsOption)
```

SetServerMetricsOptions appends gRPC server metrics options \(histogram, labels, namespace, etc.\). Must be called during initialization, before the server starts. Not safe for concurrent use.


## func [TraceIdInterceptor]()

```go
func TraceIdInterceptor() grpc.UnaryServerInterceptor
```

TraceIdInterceptor allows injecting trace id from request objects


## func [UseColdBrewClientInterceptors]()

```go
func UseColdBrewClientInterceptors(ctx context.Context, flag bool)
```

UseColdBrewClientInterceptors allows enabling/disabling coldbrew client interceptors. When set to false, the coldbrew client interceptors will not be used. Must be called during initialization, before any RPCs are made. Not safe for concurrent use.


## func [UseColdBrewServerInterceptors]()

```go
func UseColdBrewServerInterceptors(ctx context.Context, flag bool)
```

UseColdBrewServerInterceptors allows enabling/disabling coldbrew server interceptors. When set to false, the coldbrew server interceptors will not be used. Must be called during initialization, before the server starts. Not safe for concurrent use.


## type [FilterFunc]()

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

```go
type FilterFunc func(ctx context.Context, fullMethodName string) bool
```

Generated by [gomarkdoc]()