mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 20:08:02 +00:00
34 lines
869 B
Go
34 lines
869 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"go.opencensus.io/plugin/ocgrpc"
|
|
"go.opencensus.io/trace"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/stats"
|
|
|
|
"github.com/caos/zitadel/internal/tracing"
|
|
)
|
|
|
|
type GRPCMethod string
|
|
|
|
func TracingStatsServer(ignoredMethods ...GRPCMethod) grpc.ServerOption {
|
|
return grpc.StatsHandler(&tracingServerHandler{ignoredMethods, ocgrpc.ServerHandler{StartOptions: trace.StartOptions{Sampler: tracing.Sampler(), SpanKind: trace.SpanKindServer}}})
|
|
}
|
|
|
|
type tracingServerHandler struct {
|
|
IgnoredMethods []GRPCMethod
|
|
ocgrpc.ServerHandler
|
|
}
|
|
|
|
func (s *tracingServerHandler) TagRPC(ctx context.Context, tagInfo *stats.RPCTagInfo) context.Context {
|
|
for _, method := range s.IgnoredMethods {
|
|
if strings.HasSuffix(tagInfo.FullMethodName, string(method)) {
|
|
return ctx
|
|
}
|
|
}
|
|
return s.ServerHandler.TagRPC(ctx, tagInfo)
|
|
}
|