mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
fix(tracing): from opencensus to opentelemetry (#937)
* refactor: switch from opencensus to opentelemetry * tempo works as designed nooooot * fix: log traceids * with grafana agent * fix: http tracing * fix: cleanup files * chore: remove todo * fix: bad test * fix: ignore methods in grpc interceptors * fix: remove test log * clean up * typo * fix(config): configure tracing endpoint * fix(span): add error id to span
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go.opencensus.io/plugin/ocgrpc"
|
||||
"go.opencensus.io/trace"
|
||||
"google.golang.org/grpc/stats"
|
||||
)
|
||||
|
||||
func Test_tracingClientHandler_TagRPC(t *testing.T) {
|
||||
type fields struct {
|
||||
IgnoredMethods []GRPCMethod
|
||||
ClientHandler ocgrpc.ClientHandler
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
tagInfo *stats.RPCTagInfo
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantSpan bool
|
||||
}{
|
||||
{
|
||||
"ignored method",
|
||||
fields{
|
||||
IgnoredMethods: []GRPCMethod{"ignore"},
|
||||
ClientHandler: ocgrpc.ClientHandler{},
|
||||
},
|
||||
args{
|
||||
ctx: context.Background(),
|
||||
tagInfo: &stats.RPCTagInfo{
|
||||
FullMethodName: "ignore",
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"tag",
|
||||
fields{
|
||||
IgnoredMethods: []GRPCMethod{"ignore"},
|
||||
ClientHandler: ocgrpc.ClientHandler{},
|
||||
},
|
||||
args{
|
||||
ctx: context.Background(),
|
||||
tagInfo: &stats.RPCTagInfo{
|
||||
FullMethodName: "tag",
|
||||
},
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &tracingClientHandler{
|
||||
IgnoredMethods: tt.fields.IgnoredMethods,
|
||||
ClientHandler: tt.fields.ClientHandler,
|
||||
}
|
||||
got := s.TagRPC(tt.args.ctx, tt.args.tagInfo)
|
||||
if (trace.FromContext(got) != nil) != tt.wantSpan {
|
||||
t.Errorf("TagRPC() = %v, want %v", got, tt.wantSpan)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -4,44 +4,32 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"go.opencensus.io/plugin/ocgrpc"
|
||||
"go.opencensus.io/trace"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/stats"
|
||||
|
||||
grpc_utils "github.com/caos/zitadel/internal/api/grpc"
|
||||
"github.com/caos/zitadel/internal/tracing"
|
||||
grpc_trace "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type GRPCMethod string
|
||||
|
||||
func TracingStatsClient(ignoredMethods ...GRPCMethod) grpc.DialOption {
|
||||
return grpc.WithStatsHandler(
|
||||
&tracingClientHandler{
|
||||
ignoredMethods,
|
||||
ocgrpc.ClientHandler{
|
||||
StartOptions: trace.StartOptions{
|
||||
Sampler: tracing.Sampler(),
|
||||
SpanKind: trace.SpanKindClient},
|
||||
},
|
||||
},
|
||||
)
|
||||
func DefaultTracingClient() grpc.UnaryClientInterceptor {
|
||||
return TracingServer(grpc_utils.Healthz, grpc_utils.Readiness, grpc_utils.Validation)
|
||||
}
|
||||
|
||||
func DefaultTracingStatsClient() grpc.DialOption {
|
||||
return TracingStatsClient(grpc_utils.Healthz, grpc_utils.Readiness, grpc_utils.Validation)
|
||||
}
|
||||
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 {
|
||||
|
||||
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
|
||||
for _, ignoredMethod := range ignoredMethods {
|
||||
if strings.HasSuffix(method, string(ignoredMethod)) {
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
}
|
||||
}
|
||||
return grpc_trace.UnaryClientInterceptor()(ctx, method, req, reply, cc, invoker, opts...)
|
||||
}
|
||||
return s.ClientHandler.TagRPC(ctx, tagInfo)
|
||||
}
|
||||
|
Reference in New Issue
Block a user