Propagate trace contexts to shims

This adds trace context propagation over the grpc/ttrpc calls to a shim.

It also adds the otlp plugin to the runc shim so that it will send
traces to the configured tracer (which is inherited from containerd's
config).
It doesn't look like this is adding any real overhead to the runc shim's
memory usage, however it does add 2MB to the binary size.
As such this is gated by a build tag `shim_tracing`

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2024-05-07 18:24:03 +00:00
parent 03db11c3f2
commit 17d4a1357e
24 changed files with 2865 additions and 5 deletions

View File

@@ -28,6 +28,7 @@ import (
"strings"
"time"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials/insecure"
@@ -46,6 +47,7 @@ import (
"github.com/containerd/containerd/v2/pkg/timeout"
"github.com/containerd/errdefs"
"github.com/containerd/log"
"github.com/containerd/otelttrpc"
"github.com/containerd/ttrpc"
"github.com/containerd/typeurl/v2"
)
@@ -273,10 +275,16 @@ func makeConnection(ctx context.Context, id string, params client.BootstrapParam
}
}()
return ttrpc.NewClient(conn, ttrpc.WithOnClose(onClose)), nil
return ttrpc.NewClient(
conn,
ttrpc.WithOnClose(onClose),
ttrpc.WithUnaryClientInterceptor(otelttrpc.UnaryClientInterceptor()),
), nil
case "grpc":
gopts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()), //nolint:staticcheck // Ignore SA1019. Deprecation assumes use of [grpc.NewClient] but we are not using that here.
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()), //nolint:staticcheck // Ignore SA1019. Deprecation assumes use of [grpc.NewClient] but we are not using that here.
}
return grpcDialContext(params.Address, onClose, gopts...)
default: