Move tracing to plugin

This just makes the implementation a little cleaner.
It also makes the trace exporter pluggable.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2021-09-14 02:03:55 +00:00
parent 6fd80dea34
commit 084387e0b4
6 changed files with 150 additions and 121 deletions

View File

@@ -35,4 +35,5 @@ import (
_ "github.com/containerd/containerd/services/snapshots"
_ "github.com/containerd/containerd/services/tasks"
_ "github.com/containerd/containerd/services/version"
_ "github.com/containerd/containerd/tracing/plugin"
)

View File

@@ -35,12 +35,10 @@ import (
"github.com/containerd/containerd/services/server"
srvconfig "github.com/containerd/containerd/services/server/config"
"github.com/containerd/containerd/sys"
"github.com/containerd/containerd/tracing"
"github.com/containerd/containerd/version"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"go.opentelemetry.io/otel"
"google.golang.org/grpc/grpclog"
)
@@ -135,20 +133,6 @@ can be used and modified as necessary as a custom configuration.`
return err
}
// Initialize OpenTelemetry tracing
shutdown, err := tracing.InitOpenTelemetry(config)
if err != nil {
errors.Wrap(err, "failed to initialize OpenTelemetry tracing")
}
if shutdown != nil {
defer shutdown()
}
// Get a tracer
ctrdTracer := otel.Tracer("containerd")
ctx, mainCtrdSpan := ctrdTracer.Start(ctx, "containerd-exporter")
defer mainCtrdSpan.End()
// Make sure top-level directories are created early.
if err := server.CreateTopLevelDirectories(config); err != nil {
return err
@@ -300,9 +284,6 @@ can be used and modified as necessary as a custom configuration.`
func serve(ctx gocontext.Context, l net.Listener, serveFunc func(net.Listener) error) {
path := l.Addr().String()
log.G(ctx).WithField("address", path).Info("serving...")
serveSpan, ctx := tracing.StartSpan(ctx, l.Addr().String())
defer tracing.StopSpan(serveSpan)
go func() {
defer l.Close()
if err := serveFunc(l); err != nil {