2020-03-24 14:15:01 +01:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
2020-11-20 07:57:39 +01:00
|
|
|
grpc_trace "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
|
|
|
"google.golang.org/grpc"
|
2024-04-03 13:43:43 +03:00
|
|
|
|
|
|
|
grpc_utils "github.com/zitadel/zitadel/internal/api/grpc"
|
2020-03-24 14:15:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type GRPCMethod string
|
|
|
|
|
2020-11-20 07:57:39 +01:00
|
|
|
func DefaultTracingServer() grpc.UnaryServerInterceptor {
|
|
|
|
return TracingServer(grpc_utils.Healthz, grpc_utils.Readiness, grpc_utils.Validation)
|
2020-03-24 14:15:01 +01:00
|
|
|
}
|
|
|
|
|
2020-11-20 07:57:39 +01:00
|
|
|
func TracingServer(ignoredMethods ...GRPCMethod) grpc.UnaryServerInterceptor {
|
|
|
|
return func(
|
|
|
|
ctx context.Context,
|
|
|
|
req interface{},
|
|
|
|
info *grpc.UnaryServerInfo,
|
|
|
|
handler grpc.UnaryHandler,
|
|
|
|
) (interface{}, error) {
|
|
|
|
|
|
|
|
for _, ignoredMethod := range ignoredMethods {
|
|
|
|
if strings.HasSuffix(info.FullMethod, string(ignoredMethod)) {
|
|
|
|
return handler(ctx, req)
|
|
|
|
}
|
2020-03-24 14:15:01 +01:00
|
|
|
}
|
2020-11-20 07:57:39 +01:00
|
|
|
return grpc_trace.UnaryServerInterceptor()(ctx, req, info, handler)
|
2020-03-24 14:15:01 +01:00
|
|
|
}
|
|
|
|
}
|