diff --git a/README.md b/README.md
index 6d18b71..d5c6315 100644
--- a/README.md
+++ b/README.md
@@ -26,15 +26,15 @@ Interceptor configuration functions \(AddUnaryServerInterceptor, SetFilterFunc,
- [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 DefaultClientInterceptor\(defaultOpts ...any\) grpc.UnaryClientInterceptor](<#DefaultClientInterceptor>)
+- [func DefaultClientInterceptors\(defaultOpts ...any\) \[\]grpc.UnaryClientInterceptor](<#DefaultClientInterceptors>)
+- [func DefaultClientStreamInterceptor\(defaultOpts ...any\) grpc.StreamClientInterceptor](<#DefaultClientStreamInterceptor>)
+- [func DefaultClientStreamInterceptors\(defaultOpts ...any\) \[\]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 DoHTTPtoGRPC\(ctx context.Context, svr any, handler func\(ctx context.Context, req any\) \(any, error\), in any\) \(any, error\)](<#DoHTTPtoGRPC>)
- [func FilterMethodsFunc\(ctx context.Context, fullMethodName string\) bool](<#FilterMethodsFunc>)
-- [func GRPCClientInterceptor\(\_ ...interface\{\}\) grpc.UnaryClientInterceptor](<#GRPCClientInterceptor>)
+- [func GRPCClientInterceptor\(\_ ...any\) 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>)
@@ -80,7 +80,7 @@ var (
```
-## func [AddStreamClientInterceptor]()
+## func [AddStreamClientInterceptor]()
```go
func AddStreamClientInterceptor(ctx context.Context, i ...grpc.StreamClientInterceptor)
@@ -89,7 +89,7 @@ func AddStreamClientInterceptor(ctx context.Context, i ...grpc.StreamClientInter
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]()
+## func [AddStreamServerInterceptor]()
```go
func AddStreamServerInterceptor(ctx context.Context, i ...grpc.StreamServerInterceptor)
@@ -98,7 +98,7 @@ func AddStreamServerInterceptor(ctx context.Context, i ...grpc.StreamServerInter
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]()
+## func [AddUnaryClientInterceptor]()
```go
func AddUnaryClientInterceptor(ctx context.Context, i ...grpc.UnaryClientInterceptor)
@@ -107,7 +107,7 @@ func AddUnaryClientInterceptor(ctx context.Context, i ...grpc.UnaryClientInterce
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]()
+## func [AddUnaryServerInterceptor]()
```go
func AddUnaryServerInterceptor(ctx context.Context, i ...grpc.UnaryServerInterceptor)
@@ -116,7 +116,7 @@ func AddUnaryServerInterceptor(ctx context.Context, i ...grpc.UnaryServerInterce
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]()
+## func [DebugLoggingInterceptor]()
```go
func DebugLoggingInterceptor() grpc.UnaryServerInterceptor
@@ -125,43 +125,43 @@ func DebugLoggingInterceptor() grpc.UnaryServerInterceptor
DebugLoggingInterceptor is the interceptor that logs all request/response from a handler
-## func [DefaultClientInterceptor]()
+## func [DefaultClientInterceptor]()
```go
-func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptor
+func DefaultClientInterceptor(defaultOpts ...any) grpc.UnaryClientInterceptor
```
DefaultClientInterceptor are the set of default interceptors that should be applied to all client calls
-## func [DefaultClientInterceptors]()
+## func [DefaultClientInterceptors]()
```go
-func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor
+func DefaultClientInterceptors(defaultOpts ...any) []grpc.UnaryClientInterceptor
```
DefaultClientInterceptors are the set of default interceptors that should be applied to all client calls
-## func [DefaultClientStreamInterceptor]()
+## func [DefaultClientStreamInterceptor]()
```go
-func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClientInterceptor
+func DefaultClientStreamInterceptor(defaultOpts ...any) grpc.StreamClientInterceptor
```
DefaultClientStreamInterceptor are the set of default interceptors that should be applied to all stream client calls
-## func [DefaultClientStreamInterceptors]()
+## func [DefaultClientStreamInterceptors]()
```go
-func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamClientInterceptor
+func DefaultClientStreamInterceptors(defaultOpts ...any) []grpc.StreamClientInterceptor
```
DefaultClientStreamInterceptors are the set of default interceptors that should be applied to all stream client calls
-## func [DefaultInterceptors]()
+## func [DefaultInterceptors]()
```go
func DefaultInterceptors() []grpc.UnaryServerInterceptor
@@ -170,7 +170,7 @@ func DefaultInterceptors() []grpc.UnaryServerInterceptor
DefaultInterceptors are the set of default interceptors that are applied to all coldbrew methods
-## func [DefaultStreamInterceptors]()
+## func [DefaultStreamInterceptors]()
```go
func DefaultStreamInterceptors() []grpc.StreamServerInterceptor
@@ -179,10 +179,10 @@ func DefaultStreamInterceptors() []grpc.StreamServerInterceptor
DefaultStreamInterceptors are the set of default interceptors that should be applied to all coldbrew streams
-## func [DoHTTPtoGRPC]()
+## func [DoHTTPtoGRPC]()
```go
-func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error)
+func DoHTTPtoGRPC(ctx context.Context, svr any, handler func(ctx context.Context, req any) (any, error), in any) (any, error)
```
DoHTTPtoGRPC allows calling the interceptors when you use the Register\HandlerServer in grpc\-gateway. This enables in\-process HTTP\-to\-gRPC calls with the full interceptor chain \(logging, tracing, metrics, panic recovery\) without a network hop — the fastest option for gateway performance. The interceptor chain is cached on first invocation. All interceptor configuration \(AddUnaryServerInterceptor, SetFilterFunc, etc.\) must be finalized before the first call. See example below for reference.
@@ -205,7 +205,7 @@ func (s *svc) echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResp
```
-## func [FilterMethodsFunc]()
+## func [FilterMethodsFunc]()
```go
func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool
@@ -214,16 +214,16 @@ func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool
FilterMethodsFunc is the default implementation of Filter function
-## func [GRPCClientInterceptor]()
+## func [GRPCClientInterceptor]()
```go
-func GRPCClientInterceptor(_ ...interface{}) grpc.UnaryClientInterceptor
+func GRPCClientInterceptor(_ ...any) 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]()
+## func [HystrixClientInterceptor]()
```go
func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor
@@ -236,7 +236,7 @@ Note: This interceptor wraps github.com/afex/hystrix\-go which has been unmainta
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]()
+## func [NRHttpTracer]()
```go
func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)
@@ -245,7 +245,7 @@ func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)
NRHttpTracer adds newrelic tracing to this http function
-## func [NewRelicClientInterceptor]()
+## func [NewRelicClientInterceptor]()
```go
func NewRelicClientInterceptor() grpc.UnaryClientInterceptor
@@ -254,7 +254,7 @@ func NewRelicClientInterceptor() grpc.UnaryClientInterceptor
NewRelicClientInterceptor intercepts all client actions and reports them to newrelic. When NewRelic app is nil \(no license key configured\), returns a pass\-through interceptor to avoid overhead.
-## func [NewRelicInterceptor]()
+## func [NewRelicInterceptor]()
```go
func NewRelicInterceptor() grpc.UnaryServerInterceptor
@@ -263,7 +263,7 @@ func NewRelicInterceptor() grpc.UnaryServerInterceptor
NewRelicInterceptor intercepts all server actions and reports them to newrelic. When NewRelic app is nil \(no license key configured\), returns a pass\-through interceptor to avoid overhead.
-## func [OptionsInterceptor]()
+## func [OptionsInterceptor]()
```go
func OptionsInterceptor() grpc.UnaryServerInterceptor
@@ -272,7 +272,7 @@ func OptionsInterceptor() grpc.UnaryServerInterceptor
-## func [PanicRecoveryInterceptor]()
+## func [PanicRecoveryInterceptor]()
```go
func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor
@@ -281,7 +281,7 @@ func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor
-## func [ResponseTimeLoggingInterceptor]()
+## func [ResponseTimeLoggingInterceptor]()
```go
func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor
@@ -290,7 +290,7 @@ func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor
ResponseTimeLoggingInterceptor logs response time for each request on server
-## func [ResponseTimeLoggingStreamInterceptor]()
+## func [ResponseTimeLoggingStreamInterceptor]()
```go
func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor
@@ -299,7 +299,7 @@ func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor
ResponseTimeLoggingStreamInterceptor logs response time for stream RPCs.
-## func [ServerErrorInterceptor]()
+## func [ServerErrorInterceptor]()
```go
func ServerErrorInterceptor() grpc.UnaryServerInterceptor
@@ -308,7 +308,7 @@ func ServerErrorInterceptor() grpc.UnaryServerInterceptor
ServerErrorInterceptor intercepts all server actions and reports them to error notifier
-## func [ServerErrorStreamInterceptor]()
+## func [ServerErrorStreamInterceptor]()
```go
func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor
@@ -317,7 +317,7 @@ func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor
ServerErrorStreamInterceptor intercepts server errors for stream RPCs and reports them to the error notifier.
-## func [SetClientMetricsOptions]()
+## func [SetClientMetricsOptions]()
```go
func SetClientMetricsOptions(opts ...grpcprom.ClientMetricsOption)
@@ -326,7 +326,7 @@ 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]()
+## func [SetFilterFunc]()
```go
func SetFilterFunc(ctx context.Context, ff FilterFunc)
@@ -335,7 +335,7 @@ 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 [SetFilterMethods]()
+## func [SetFilterMethods]()
```go
func SetFilterMethods(ctx context.Context, methods []string)
@@ -344,7 +344,7 @@ func SetFilterMethods(ctx context.Context, methods []string)
SetFilterMethods sets the list of method substrings to exclude from tracing/logging. It rebuilds the internal cache. Must be called during initialization, before the server starts. Not safe for concurrent use.
-## func [SetResponseTimeLogErrorOnly]()
+## func [SetResponseTimeLogErrorOnly]()
```go
func SetResponseTimeLogErrorOnly(errorOnly bool)
@@ -353,7 +353,7 @@ func SetResponseTimeLogErrorOnly(errorOnly bool)
SetResponseTimeLogErrorOnly when set to true, only logs response time when the request returns an error. Successful requests are not logged. Must be called during initialization, before the server starts. Not safe for concurrent use.
-## func [SetResponseTimeLogLevel]()
+## func [SetResponseTimeLogLevel]()
```go
func SetResponseTimeLogLevel(ctx context.Context, level loggers.Level)
@@ -362,7 +362,7 @@ 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]()
+## func [SetServerMetricsOptions]()
```go
func SetServerMetricsOptions(opts ...grpcprom.ServerMetricsOption)
@@ -371,7 +371,7 @@ 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]()
+## func [TraceIdInterceptor]()
```go
func TraceIdInterceptor() grpc.UnaryServerInterceptor
@@ -380,7 +380,7 @@ func TraceIdInterceptor() grpc.UnaryServerInterceptor
TraceIdInterceptor allows injecting trace id from request objects
-## func [UseColdBrewClientInterceptors]()
+## func [UseColdBrewClientInterceptors]()
```go
func UseColdBrewClientInterceptors(ctx context.Context, flag bool)
@@ -389,7 +389,7 @@ 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]()
+## func [UseColdBrewServerInterceptors]()
```go
func UseColdBrewServerInterceptors(ctx context.Context, flag bool)
@@ -398,7 +398,7 @@ 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]()
+## type [FilterFunc]()
If it returns false, the given request will not be traced.
diff --git a/go.mod b/go.mod
index 81714d7..7fdd872 100644
--- a/go.mod
+++ b/go.mod
@@ -4,8 +4,8 @@ go 1.25.8
require (
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
- github.com/go-coldbrew/errors v0.2.12
- github.com/go-coldbrew/log v0.3.0
+ github.com/go-coldbrew/errors v0.2.13
+ github.com/go-coldbrew/log v0.3.1
github.com/go-coldbrew/options v0.3.0
github.com/go-coldbrew/tracing v0.2.0
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.1.0
diff --git a/go.sum b/go.sum
index d36e743..2cb44ce 100644
--- a/go.sum
+++ b/go.sum
@@ -169,10 +169,10 @@ github.com/ghostiam/protogetter v0.3.20 h1:oW7OPFit2FxZOpmMRPP9FffU4uUpfeE/rEdE1
github.com/ghostiam/protogetter v0.3.20/go.mod h1:FjIu5Yfs6FT391m+Fjp3fbAYJ6rkL/J6ySpZBfnODuI=
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
-github.com/go-coldbrew/errors v0.2.12 h1:pySZsaQgH+UoTWkytpIVgvnmMR0kL27VzJtTusUGMZA=
-github.com/go-coldbrew/errors v0.2.12/go.mod h1:eFLqeTPhgGyvsVVRXcdKGUxEnm+chrpddhL8lfogonk=
-github.com/go-coldbrew/log v0.3.0 h1:oYaAq6rS4hJGMVUQgF0xav2uw3LZeMcQrnKQcUl9Vaw=
-github.com/go-coldbrew/log v0.3.0/go.mod h1:xxZGHBfni5eXc6Azg+g8UPTmqTJLAf9sX46gAT8o39Y=
+github.com/go-coldbrew/errors v0.2.13 h1:OUOEWLml6Mstt0Sskc94VVPhZ/rMfONeNOlHqycaq1g=
+github.com/go-coldbrew/errors v0.2.13/go.mod h1:eFLqeTPhgGyvsVVRXcdKGUxEnm+chrpddhL8lfogonk=
+github.com/go-coldbrew/log v0.3.1 h1:Cyx6KWBW3wZE8dSru6mIDFtUnJ1R2h6C44ZDo5bOqAo=
+github.com/go-coldbrew/log v0.3.1/go.mod h1:xxZGHBfni5eXc6Azg+g8UPTmqTJLAf9sX46gAT8o39Y=
github.com/go-coldbrew/options v0.3.0 h1:JwyVntb9bzBeFdaHFK6yGVVz30G3aVlqJJ6uVyYQfCc=
github.com/go-coldbrew/options v0.3.0/go.mod h1:8JlmgVJXFoY1KiDLsyMmR//q1U1aBItCexvTrVT2Y60=
github.com/go-coldbrew/tracing v0.2.0 h1:WGfdp5PNunOGfjTZGXPFaip3G5qOOMP622JFYA90ML4=
diff --git a/interceptors.go b/interceptors.go
index 484c23e..1c0d818 100644
--- a/interceptors.go
+++ b/interceptors.go
@@ -11,6 +11,7 @@ import (
"fmt"
"net/http"
"runtime/debug"
+ "slices"
"strings"
"sync"
"sync/atomic"
@@ -264,12 +265,12 @@ func getClientMetrics() *grpcprom.ClientMetrics {
// chainUnaryServer chains multiple unary server interceptors into one.
func chainUnaryServer(interceptors []grpc.UnaryServerInterceptor) grpc.UnaryServerInterceptor {
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
chain := handler
for i := len(interceptors) - 1; i >= 0; i-- {
interceptor := interceptors[i]
next := chain
- chain = func(ctx context.Context, req interface{}) (interface{}, error) {
+ chain = func(ctx context.Context, req any) (any, error) {
return interceptor(ctx, req, info, next)
}
}
@@ -279,12 +280,12 @@ func chainUnaryServer(interceptors []grpc.UnaryServerInterceptor) grpc.UnaryServ
// chainUnaryClient chains multiple unary client interceptors into one.
func chainUnaryClient(interceptors []grpc.UnaryClientInterceptor) grpc.UnaryClientInterceptor {
- return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+ return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
chain := invoker
for i := len(interceptors) - 1; i >= 0; i-- {
interceptor := interceptors[i]
next := chain
- chain = func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
+ chain = func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
return interceptor(ctx, method, req, reply, cc, next, opts...)
}
}
@@ -340,7 +341,7 @@ func getHTTPtoGRPCInterceptor() grpc.UnaryServerInterceptor {
// func (s *svc) echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
// .... implementation ....
// }
-func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error) {
+func DoHTTPtoGRPC(ctx context.Context, svr any, handler func(ctx context.Context, req any) (any, error), in any) (any, error) {
method, ok := runtime.RPCMethod(ctx)
if ok {
interceptor := getHTTPtoGRPCInterceptor()
@@ -373,7 +374,7 @@ func DefaultInterceptors() []grpc.UnaryServerInterceptor {
}
// DefaultClientInterceptors are the set of default interceptors that should be applied to all client calls
-func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor {
+func DefaultClientInterceptors(defaultOpts ...any) []grpc.UnaryClientInterceptor {
ints := []grpc.UnaryClientInterceptor{}
if len(unaryClientInterceptors) > 0 {
ints = append(ints, unaryClientInterceptors...)
@@ -399,7 +400,7 @@ func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInt
}
// DefaultClientStreamInterceptors are the set of default interceptors that should be applied to all stream client calls
-func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamClientInterceptor {
+func DefaultClientStreamInterceptors(defaultOpts ...any) []grpc.StreamClientInterceptor {
ints := []grpc.StreamClientInterceptor{}
if len(streamClientInterceptors) > 0 {
ints = append(ints, streamClientInterceptors...)
@@ -430,18 +431,18 @@ func DefaultStreamInterceptors() []grpc.StreamServerInterceptor {
}
// DefaultClientInterceptor are the set of default interceptors that should be applied to all client calls
-func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptor {
+func DefaultClientInterceptor(defaultOpts ...any) grpc.UnaryClientInterceptor {
return chainUnaryClient(DefaultClientInterceptors(defaultOpts...))
}
// DefaultClientStreamInterceptor are the set of default interceptors that should be applied to all stream client calls
-func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClientInterceptor {
+func DefaultClientStreamInterceptor(defaultOpts ...any) grpc.StreamClientInterceptor {
return chainStreamClient(DefaultClientStreamInterceptors(defaultOpts...))
}
// DebugLoggingInterceptor is the interceptor that logs all request/response from a handler
func DebugLoggingInterceptor() grpc.UnaryServerInterceptor {
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
log.Debug(ctx, "method", info.FullMethod, "request", req)
resp, err := handler(ctx, req)
log.Debug(ctx, "method", info.FullMethod, "response", resp, "err", err)
@@ -451,7 +452,7 @@ func DebugLoggingInterceptor() grpc.UnaryServerInterceptor {
// ResponseTimeLoggingInterceptor logs response time for each request on server
func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor {
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
ctx = loggers.AddToLogContext(ctx, "grpcMethod", info.FullMethod)
defer func(ctx context.Context, method string, begin time.Time) {
if ff != nil && !ff(ctx, method) {
@@ -473,7 +474,7 @@ func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor {
}
func OptionsInterceptor() grpc.UnaryServerInterceptor {
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
ctx = options.AddToOptions(ctx, "", "")
// loggers.AddToLogContext(ctx, "transport", "gRPC")
return handler(ctx, req)
@@ -486,12 +487,12 @@ func OptionsInterceptor() grpc.UnaryServerInterceptor {
func NewRelicInterceptor() grpc.UnaryServerInterceptor {
app := nrutil.GetNewRelicApp()
if app == nil {
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
return handler(ctx, req)
}
}
nrh := nrgrpc.UnaryServerInterceptor(app)
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
if defaultFilterFunc(ctx, info.FullMethod) {
return nrh(ctx, req, info, handler)
} else {
@@ -502,7 +503,7 @@ func NewRelicInterceptor() grpc.UnaryServerInterceptor {
// ServerErrorInterceptor intercepts all server actions and reports them to error notifier
func ServerErrorInterceptor() grpc.UnaryServerInterceptor {
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
// set trace id if not set
ctx, _ = notifier.SetTraceIdWithValue(ctx)
start := time.Now()
@@ -518,7 +519,7 @@ func ServerErrorInterceptor() grpc.UnaryServerInterceptor {
}
func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor {
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
defer func(ctx context.Context) {
// panic handler
if r := recover(); r != nil {
@@ -545,11 +546,11 @@ func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor {
func NewRelicClientInterceptor() grpc.UnaryClientInterceptor {
app := nrutil.GetNewRelicApp()
if app == nil {
- return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+ return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
return invoker(ctx, method, req, reply, cc, opts...)
}
}
- return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+ return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
if defaultFilterFunc(ctx, method) {
return nrgrpc.UnaryClientInterceptor(ctx, method, req, reply, cc, invoker, opts...)
} else {
@@ -561,8 +562,8 @@ func NewRelicClientInterceptor() 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 GRPCClientInterceptor(_ ...interface{}) grpc.UnaryClientInterceptor {
- return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+func GRPCClientInterceptor(_ ...any) grpc.UnaryClientInterceptor {
+ return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
return invoker(ctx, method, req, reply, cc, opts...)
}
}
@@ -576,7 +577,7 @@ func GRPCClientInterceptor(_ ...interface{}) grpc.UnaryClientInterceptor {
// 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 {
+ return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
options := clientOptions{
hystrixName: method,
}
@@ -617,10 +618,8 @@ func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientIn
}
}
if st, ok := status.FromError(invokerErr); ok {
- for _, code := range options.excludedCodes {
- if st.Code() == code {
- return nil
- }
+ if slices.Contains(options.excludedCodes, st.Code()) {
+ return nil
}
}
return invokerErr
@@ -634,7 +633,7 @@ func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientIn
// ResponseTimeLoggingStreamInterceptor logs response time for stream RPCs.
func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor {
- return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error) {
+ return func(srv any, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error) {
defer func(begin time.Time) {
if responseTimeLogErrorOnly && err == nil {
return
@@ -654,7 +653,7 @@ func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor {
// ServerErrorStreamInterceptor intercepts server errors for stream RPCs and
// reports them to the error notifier.
func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor {
- return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error) {
+ return func(srv any, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error) {
ctx := stream.Context()
ctx, _ = notifier.SetTraceIdWithValue(ctx)
start := time.Now()
@@ -693,7 +692,7 @@ func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)
// TraceIdInterceptor allows injecting trace id from request objects
func TraceIdInterceptor() grpc.UnaryServerInterceptor {
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
if req != nil {
// fetch and update trace id from request
if r, ok := req.(interface{ GetTraceId() string }); ok {
diff --git a/interceptors_test.go b/interceptors_test.go
index 52a47af..77ef410 100644
--- a/interceptors_test.go
+++ b/interceptors_test.go
@@ -18,10 +18,10 @@ import (
// mockStream implements grpc.ServerTransportStream for testing.
type mockStream struct{ method string }
-func (s *mockStream) Method() string { return s.method }
-func (s *mockStream) SetHeader(grpcmd.MD) error { return nil }
-func (s *mockStream) SendHeader(grpcmd.MD) error { return nil }
-func (s *mockStream) SetTrailer(grpcmd.MD) error { return nil }
+func (s *mockStream) Method() string { return s.method }
+func (s *mockStream) SetHeader(grpcmd.MD) error { return nil }
+func (s *mockStream) SendHeader(grpcmd.MD) error { return nil }
+func (s *mockStream) SetTrailer(grpcmd.MD) error { return nil }
// grpcContext returns a context that grpc.Method() recognizes as a gRPC server context.
func grpcContext() context.Context {
@@ -132,7 +132,7 @@ func TestFilterMethodsFunc_HTTPPathNotCached(t *testing.T) {
// Verify nothing was cached.
f := currentFilter.Load()
cached := 0
- f.cache.Range(func(_, _ interface{}) bool {
+ f.cache.Range(func(_, _ any) bool {
cached++
return true
})
@@ -146,7 +146,7 @@ func TestAddUnaryServerInterceptor(t *testing.T) {
ctx := context.Background()
called := false
- interceptor := func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ interceptor := func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
called = true
return handler(ctx, req)
}
@@ -160,7 +160,7 @@ func TestAddUnaryServerInterceptor(t *testing.T) {
// The user interceptor should be the first one.
info := &grpc.UnaryServerInfo{FullMethod: "/test/Method"}
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
return "ok", nil
}
_, _ = ints[0](ctx, nil, info, handler)
@@ -182,7 +182,7 @@ func TestDefaultInterceptors_Disabled(t *testing.T) {
// Add a user interceptor and verify it still shows up.
userCalled := false
- AddUnaryServerInterceptor(ctx, func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ AddUnaryServerInterceptor(ctx, func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
userCalled = true
return handler(ctx, req)
})
@@ -192,7 +192,7 @@ func TestDefaultInterceptors_Disabled(t *testing.T) {
}
info := &grpc.UnaryServerInfo{FullMethod: "/test/Method"}
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
return "ok", nil
}
_, _ = ints[0](ctx, nil, info, handler)
@@ -206,7 +206,7 @@ func TestPanicRecoveryInterceptor(t *testing.T) {
interceptor := PanicRecoveryInterceptor()
info := &grpc.UnaryServerInfo{FullMethod: "/test/Panic"}
- panicHandler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ panicHandler := func(ctx context.Context, req any) (any, error) {
panic("test panic")
}
@@ -224,7 +224,7 @@ func TestPanicRecoveryInterceptor(t *testing.T) {
// Panic with an error value should return that error.
errPanic := fmt.Errorf("error panic")
- panicHandler2 := func(ctx context.Context, req interface{}) (interface{}, error) {
+ panicHandler2 := func(ctx context.Context, req any) (any, error) {
panic(errPanic)
}
_, err = interceptor(ctx, nil, info, panicHandler2)
@@ -239,7 +239,7 @@ func TestResponseTimeLoggingInterceptor(t *testing.T) {
info := &grpc.UnaryServerInfo{FullMethod: "/test/Method"}
handlerCalled := false
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
handlerCalled = true
return "response", nil
}
@@ -262,7 +262,7 @@ func TestDebugLoggingInterceptor(t *testing.T) {
info := &grpc.UnaryServerInfo{FullMethod: "/test/Debug"}
handlerCalled := false
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
handlerCalled = true
return "debug_resp", nil
}
@@ -287,7 +287,7 @@ func TestDoHTTPtoGRPC(t *testing.T) {
UseColdBrewServerInterceptors(ctx, false)
handlerCalled := false
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
handlerCalled = true
return "result", nil
}
@@ -308,7 +308,7 @@ func TestDoHTTPtoGRPC(t *testing.T) {
// the interceptor chain should NOT be invoked.
handlerCalled = false
interceptorCalled := false
- AddUnaryServerInterceptor(ctx, func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ AddUnaryServerInterceptor(ctx, func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
interceptorCalled = true
return handler(ctx, req)
})
@@ -356,7 +356,7 @@ func TestHystrixClientInterceptor(t *testing.T) {
t.Run("basic invocation", func(t *testing.T) {
interceptor := HystrixClientInterceptor()
invokerCalled := false
- invoker := func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
+ invoker := func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
invokerCalled = true
return nil
}
@@ -373,7 +373,7 @@ func TestHystrixClientInterceptor(t *testing.T) {
t.Run("WithoutHystrix short-circuits", func(t *testing.T) {
interceptor := HystrixClientInterceptor()
invokerCalled := false
- invoker := func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
+ invoker := func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
invokerCalled = true
return nil
}
@@ -391,7 +391,7 @@ func TestHystrixClientInterceptor(t *testing.T) {
func TestChainUnaryServer(t *testing.T) {
var order []int
makeInterceptor := func(id int) grpc.UnaryServerInterceptor {
- return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
order = append(order, id)
return handler(ctx, req)
}
@@ -404,7 +404,7 @@ func TestChainUnaryServer(t *testing.T) {
})
info := &grpc.UnaryServerInfo{FullMethod: "/test/Chain"}
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
order = append(order, 0) // handler marker
return "ok", nil
}
@@ -424,7 +424,7 @@ func TestChainUnaryServer(t *testing.T) {
func TestChainUnaryClient(t *testing.T) {
var order []int
makeInterceptor := func(id int) grpc.UnaryClientInterceptor {
- return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+ return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
order = append(order, id)
return invoker(ctx, method, req, reply, cc, opts...)
}
@@ -436,7 +436,7 @@ func TestChainUnaryClient(t *testing.T) {
makeInterceptor(3),
})
- invoker := func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
+ invoker := func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
order = append(order, 0)
return nil
}
@@ -485,24 +485,22 @@ func TestChainStreamClient(t *testing.T) {
// Run with -race to detect violations.
func TestChainUnaryServerConcurrent(t *testing.T) {
chain := chainUnaryServer([]grpc.UnaryServerInterceptor{
- func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
return handler(ctx, req.(string)+"-A")
},
- func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
return handler(ctx, req.(string)+"-B")
},
})
info := &grpc.UnaryServerInfo{FullMethod: "/test/Concurrent"}
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
return req.(string) + "-handler", nil
}
var wg sync.WaitGroup
- for i := 0; i < 100; i++ {
- wg.Add(1)
- go func() {
- defer wg.Done()
+ for range 100 {
+ wg.Go(func() {
resp, err := chain(context.Background(), "start", info, handler)
if err != nil {
t.Errorf("unexpected error: %v", err)
@@ -510,7 +508,7 @@ func TestChainUnaryServerConcurrent(t *testing.T) {
if resp != "start-A-B-handler" {
t.Errorf("expected 'start-A-B-handler', got %v", resp)
}
- }()
+ })
}
wg.Wait()
}
@@ -519,21 +517,19 @@ func TestChainUnaryServerConcurrent(t *testing.T) {
// for concurrent use and produces the correct output from each goroutine.
func TestChainUnaryClientConcurrent(t *testing.T) {
chain := chainUnaryClient([]grpc.UnaryClientInterceptor{
- func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+ func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
return invoker(ctx, method+"-A", req, reply, cc, opts...)
},
- func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+ func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
return invoker(ctx, method+"-B", req, reply, cc, opts...)
},
})
var wg sync.WaitGroup
- for i := 0; i < 100; i++ {
- wg.Add(1)
- go func() {
- defer wg.Done()
+ for range 100 {
+ wg.Go(func() {
var got string
- invoker := func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
+ invoker := func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
got = method
return nil
}
@@ -544,7 +540,7 @@ func TestChainUnaryClientConcurrent(t *testing.T) {
if got != "/svc/Call-A-B" {
t.Errorf("expected '/svc/Call-A-B', got %v", got)
}
- }()
+ })
}
wg.Wait()
}
@@ -562,10 +558,8 @@ func TestChainStreamClientConcurrent(t *testing.T) {
})
var wg sync.WaitGroup
- for i := 0; i < 100; i++ {
- wg.Add(1)
- go func() {
- defer wg.Done()
+ for range 100 {
+ wg.Go(func() {
var got string
streamer := func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) {
got = method
@@ -578,7 +572,7 @@ func TestChainStreamClientConcurrent(t *testing.T) {
if got != "/svc/Stream-A-B" {
t.Errorf("expected '/svc/Stream-A-B', got %v", got)
}
- }()
+ })
}
wg.Wait()
}
@@ -587,7 +581,7 @@ func TestGRPCClientInterceptorNoOp(t *testing.T) {
interceptor := GRPCClientInterceptor()
invoked := false
- mockInvoker := func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
+ mockInvoker := func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
invoked = true
return nil
}
@@ -639,12 +633,12 @@ func BenchmarkFilterMethodsFunc(b *testing.B) {
}
// noopHandler is a handler that returns immediately with no error.
-var noopHandler grpc.UnaryHandler = func(ctx context.Context, req interface{}) (interface{}, error) {
+var noopHandler grpc.UnaryHandler = func(ctx context.Context, req any) (any, error) {
return "ok", nil
}
// errHandler is a handler that returns an error.
-var errHandler grpc.UnaryHandler = func(ctx context.Context, req interface{}) (interface{}, error) {
+var errHandler grpc.UnaryHandler = func(ctx context.Context, req any) (any, error) {
return nil, errors.New("test error")
}
@@ -726,8 +720,8 @@ func BenchmarkDefaultInterceptors(b *testing.B) {
for i := len(chain) - 1; i >= 0; i-- {
next := chainedHandler
interceptor := chain[i]
- chainedHandler = func(ctx context.Context, req interface{}) (interface{}, error) {
- return interceptor(ctx, req, benchInfo, func(ctx context.Context, req interface{}) (interface{}, error) {
+ chainedHandler = func(ctx context.Context, req any) (any, error) {
+ return interceptor(ctx, req, benchInfo, func(ctx context.Context, req any) (any, error) {
return next(ctx, req)
})
}
@@ -747,7 +741,7 @@ func TestNewRelicInterceptor_NilApp(t *testing.T) {
info := &grpc.UnaryServerInfo{FullMethod: "/test.Service/Method"}
handlerCalled := false
- resp, err := interceptor(ctx, "request", info, func(ctx context.Context, req interface{}) (interface{}, error) {
+ resp, err := interceptor(ctx, "request", info, func(ctx context.Context, req any) (any, error) {
handlerCalled = true
return "response", nil
})
@@ -765,7 +759,7 @@ func TestNewRelicClientInterceptor_NilApp(t *testing.T) {
invokerCalled := false
err := interceptor(context.Background(), "/test.Service/Method", nil, nil, nil,
- func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
+ func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
invokerCalled = true
return nil
})
@@ -786,7 +780,7 @@ func TestResponseTimeLogErrorOnly_SkipsSuccess(t *testing.T) {
ctx := grpcContext()
info := &grpc.UnaryServerInfo{FullMethod: "/test.Service/Method"}
- resp, err := interceptor(ctx, nil, info, func(ctx context.Context, req interface{}) (interface{}, error) {
+ resp, err := interceptor(ctx, nil, info, func(ctx context.Context, req any) (any, error) {
return "ok", nil
})
if resp != "ok" || err != nil {
@@ -807,7 +801,7 @@ func TestResponseTimeLogErrorOnly_LogsErrors(t *testing.T) {
info := &grpc.UnaryServerInfo{FullMethod: "/test.Service/Method"}
testErr := errors.New("handler failed")
- resp, err := interceptor(ctx, nil, info, func(ctx context.Context, req interface{}) (interface{}, error) {
+ resp, err := interceptor(ctx, nil, info, func(ctx context.Context, req any) (any, error) {
return nil, testErr
})
if resp != nil {
@@ -823,7 +817,7 @@ func TestDoHTTPtoGRPC_HandlerError(t *testing.T) {
UseColdBrewServerInterceptors(context.Background(), false)
testErr := errors.New("handler failed")
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
return nil, testErr
}
@@ -857,12 +851,12 @@ func TestDoHTTPtoGRPC_MethodPassedToInfo(t *testing.T) {
UseColdBrewServerInterceptors(context.Background(), false)
var capturedMethod string
- AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
capturedMethod = info.FullMethod
return handler(ctx, req)
})
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
return "ok", nil
}
@@ -886,8 +880,8 @@ func TestDoHTTPtoGRPC_InputPassedThrough(t *testing.T) {
defer resetGlobals()
UseColdBrewServerInterceptors(context.Background(), false)
- var capturedReq interface{}
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ var capturedReq any
+ handler := func(ctx context.Context, req any) (any, error) {
capturedReq = req
return "ok", nil
}
@@ -924,13 +918,13 @@ func TestDoHTTPtoGRPC_ServerPassedToInfo(t *testing.T) {
type fakeServer struct{ Name string }
svr := &fakeServer{Name: "test-server"}
- var capturedServer interface{}
- AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ var capturedServer any
+ AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
capturedServer = info.Server
return handler(ctx, req)
})
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
return "ok", nil
}
@@ -955,12 +949,12 @@ func TestDoHTTPtoGRPC_Concurrent(t *testing.T) {
UseColdBrewServerInterceptors(context.Background(), false)
var callCount int64
- AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
atomic.AddInt64(&callCount, 1)
return handler(ctx, req)
})
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
return req, nil
}
@@ -973,7 +967,7 @@ func TestDoHTTPtoGRPC_Concurrent(t *testing.T) {
const goroutines = 50
var wg sync.WaitGroup
- for i := 0; i < goroutines; i++ {
+ for i := range goroutines {
wg.Add(1)
go func(n int) {
defer wg.Done()
@@ -998,11 +992,11 @@ func TestDoHTTPtoGRPC_InterceptorCaching(t *testing.T) {
defer resetGlobals()
UseColdBrewServerInterceptors(context.Background(), false)
- AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
return handler(ctx, req)
})
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ handler := func(ctx context.Context, req any) (any, error) {
return "ok", nil
}
@@ -1023,7 +1017,7 @@ func TestDoHTTPtoGRPC_InterceptorCaching(t *testing.T) {
// Adding a new interceptor after first call should NOT affect the cached chain.
interceptor2Called := false
- AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ AddUnaryServerInterceptor(context.Background(), func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
interceptor2Called = true
return handler(ctx, req)
})