mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit to opentelemetry support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
38
vendor/github.com/moby/buildkit/session/session.go
generated
vendored
38
vendor/github.com/moby/buildkit/session/session.go
generated
vendored
@ -6,11 +6,12 @@ import (
|
||||
"strings"
|
||||
|
||||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
|
||||
"github.com/moby/buildkit/identity"
|
||||
"github.com/moby/buildkit/util/grpcerrors"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/pkg/errors"
|
||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/health"
|
||||
"google.golang.org/grpc/health/grpc_health_v1"
|
||||
@ -23,6 +24,8 @@ const (
|
||||
headerSessionMethod = "X-Docker-Expose-Session-Grpc-Method"
|
||||
)
|
||||
|
||||
var propagators = propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})
|
||||
|
||||
// Dialer returns a connection that can be used by the session
|
||||
type Dialer func(ctx context.Context, proto string, meta map[string][]string) (net.Conn, error)
|
||||
|
||||
@ -51,10 +54,10 @@ func NewSession(ctx context.Context, name, sharedKey string) (*Session, error) {
|
||||
var stream []grpc.StreamServerInterceptor
|
||||
|
||||
serverOpts := []grpc.ServerOption{}
|
||||
if span := opentracing.SpanFromContext(ctx); span != nil {
|
||||
tracer := span.Tracer()
|
||||
unary = append(unary, otgrpc.OpenTracingServerInterceptor(tracer, traceFilter()))
|
||||
stream = append(stream, otgrpc.OpenTracingStreamServerInterceptor(span.Tracer(), traceFilter()))
|
||||
|
||||
if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {
|
||||
unary = append(unary, filterServer(otelgrpc.UnaryServerInterceptor(otelgrpc.WithTracerProvider(span.TracerProvider()), otelgrpc.WithPropagators(propagators))))
|
||||
stream = append(stream, otelgrpc.StreamServerInterceptor(otelgrpc.WithTracerProvider(span.TracerProvider()), otelgrpc.WithPropagators(propagators)))
|
||||
}
|
||||
|
||||
unary = append(unary, grpcerrors.UnaryServerInterceptor)
|
||||
@ -152,10 +155,21 @@ func MethodURL(s, m string) string {
|
||||
return "/" + s + "/" + m
|
||||
}
|
||||
|
||||
func traceFilter() otgrpc.Option {
|
||||
return otgrpc.IncludingSpans(func(parentSpanCtx opentracing.SpanContext,
|
||||
method string,
|
||||
req, resp interface{}) bool {
|
||||
return !strings.HasSuffix(method, "Health/Check")
|
||||
})
|
||||
// updates needed in opentelemetry-contrib to avoid this
|
||||
func filterServer(intercept grpc.UnaryServerInterceptor) grpc.UnaryServerInterceptor {
|
||||
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
||||
if strings.HasSuffix(info.FullMethod, "Health/Check") {
|
||||
return handler(ctx, req)
|
||||
}
|
||||
return intercept(ctx, req, info, handler)
|
||||
}
|
||||
}
|
||||
|
||||
func filterClient(intercept grpc.UnaryClientInterceptor) grpc.UnaryClientInterceptor {
|
||||
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
||||
if strings.HasSuffix(method, "Health/Check") {
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
}
|
||||
return intercept(ctx, method, req, reply, cc, invoker, opts...)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user