2020-03-24 13:15:01 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
grpc_utils "github.com/zitadel/zitadel/internal/api/grpc"
|
2020-11-20 06:57:39 +00:00
|
|
|
grpc_trace "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
|
|
|
"google.golang.org/grpc"
|
2020-03-24 13:15:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type GRPCMethod string
|
|
|
|
|
2020-11-20 06:57:39 +00:00
|
|
|
func DefaultTracingClient() grpc.UnaryClientInterceptor {
|
|
|
|
return TracingServer(grpc_utils.Healthz, grpc_utils.Readiness, grpc_utils.Validation)
|
2020-03-24 13:15:01 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 06:57:39 +00:00
|
|
|
func TracingServer(ignoredMethods ...GRPCMethod) grpc.UnaryClientInterceptor {
|
|
|
|
return func(
|
|
|
|
ctx context.Context,
|
|
|
|
method string,
|
|
|
|
req, reply interface{},
|
|
|
|
cc *grpc.ClientConn,
|
|
|
|
invoker grpc.UnaryInvoker,
|
|
|
|
opts ...grpc.CallOption,
|
|
|
|
) error {
|
|
|
|
|
|
|
|
for _, ignoredMethod := range ignoredMethods {
|
|
|
|
if strings.HasSuffix(method, string(ignoredMethod)) {
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
}
|
2020-03-24 13:15:01 +00:00
|
|
|
}
|
2020-11-20 06:57:39 +00:00
|
|
|
return grpc_trace.UnaryClientInterceptor()(ctx, method, req, reply, cc, invoker, opts...)
|
2020-03-24 13:15:01 +00:00
|
|
|
}
|
|
|
|
}
|