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:
21
cmd/containerd-shim-runc-v2/main_tracing.go
Normal file
21
cmd/containerd-shim-runc-v2/main_tracing.go
Normal file
@@ -0,0 +1,21 @@
|
||||
//go:build shim_tracing
|
||||
|
||||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import _ "github.com/containerd/containerd/v2/pkg/tracing/plugin"
|
||||
@@ -104,6 +104,7 @@ func newCommand(ctx context.Context, id, containerdAddress, containerdTTRPCAddre
|
||||
cmd := exec.Command(self, args...)
|
||||
cmd.Dir = cwd
|
||||
cmd.Env = append(os.Environ(), "GOMAXPROCS=4")
|
||||
cmd.Env = append(cmd.Env, "OTEL_SERVICE_NAME=containerd-shim-"+id)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
srvconfig "github.com/containerd/containerd/v2/cmd/containerd/server/config"
|
||||
"github.com/containerd/containerd/v2/pkg/sys"
|
||||
"github.com/containerd/log"
|
||||
"github.com/containerd/otelttrpc"
|
||||
"github.com/containerd/ttrpc"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
@@ -66,5 +67,8 @@ func apply(ctx context.Context, config *srvconfig.Config) error {
|
||||
}
|
||||
|
||||
func newTTRPCServer() (*ttrpc.Server, error) {
|
||||
return ttrpc.NewServer(ttrpc.WithServerHandshaker(ttrpc.UnixSocketRequireSameUser()))
|
||||
return ttrpc.NewServer(
|
||||
ttrpc.WithServerHandshaker(ttrpc.UnixSocketRequireSameUser()),
|
||||
ttrpc.WithUnaryServerInterceptor(otelttrpc.UnaryServerInterceptor()),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
|
||||
srvconfig "github.com/containerd/containerd/v2/cmd/containerd/server/config"
|
||||
"github.com/containerd/otelttrpc"
|
||||
"github.com/containerd/ttrpc"
|
||||
)
|
||||
|
||||
@@ -28,5 +29,7 @@ func apply(_ context.Context, _ *srvconfig.Config) error {
|
||||
}
|
||||
|
||||
func newTTRPCServer() (*ttrpc.Server, error) {
|
||||
return ttrpc.NewServer()
|
||||
return ttrpc.NewServer(
|
||||
ttrpc.WithUnaryServerInterceptor(otelttrpc.UnaryServerInterceptor()),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user