2020-03-24 13:15:01 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.opencensus.io/plugin/ocgrpc"
|
|
|
|
"go.opencensus.io/trace"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/stats"
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
"github.com/caos/zitadel/internal/api/http"
|
2020-03-24 13:15:01 +00:00
|
|
|
"github.com/caos/zitadel/internal/tracing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GRPCMethod string
|
|
|
|
|
|
|
|
func TracingStatsClient(ignoredMethods ...GRPCMethod) grpc.DialOption {
|
2020-07-08 11:56:37 +00:00
|
|
|
return grpc.WithStatsHandler(
|
|
|
|
&tracingClientHandler{
|
|
|
|
ignoredMethods,
|
|
|
|
ocgrpc.ClientHandler{
|
|
|
|
StartOptions: trace.StartOptions{
|
|
|
|
Sampler: tracing.Sampler(),
|
|
|
|
SpanKind: trace.SpanKindClient},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2020-03-24 13:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultTracingStatsClient() grpc.DialOption {
|
2020-07-08 11:56:37 +00:00
|
|
|
return TracingStatsClient(http.Healthz, http.Readiness, http.Validation)
|
2020-03-24 13:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type tracingClientHandler struct {
|
|
|
|
IgnoredMethods []GRPCMethod
|
|
|
|
ocgrpc.ClientHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *tracingClientHandler) 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.ClientHandler.TagRPC(ctx, tagInfo)
|
|
|
|
}
|