From efd82e1e314bf1c87cdff1859a7fdfc1c6e2cc87 Mon Sep 17 00:00:00 2001 From: Christopher Petito Date: Thu, 28 Mar 2024 16:23:01 +0000 Subject: [PATCH] Initial otel impl using our utils Signed-off-by: Christopher Petito --- cmd/docker/docker.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index c79bfaaa0d..1b871289ee 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "os" "os/exec" @@ -21,17 +22,19 @@ import ( "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" + "go.opentelemetry.io/otel" ) func main() { - dockerCli, err := command.NewDockerCli() + ctx := context.Background() + dockerCli, err := command.NewDockerCli(command.WithBaseContext(ctx)) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } logrus.SetOutput(dockerCli.Err()) - if err := runDocker(dockerCli); err != nil { + if err := runDocker(ctx, dockerCli); err != nil { if sterr, ok := err.(cli.StatusError); ok { if sterr.Status != "" { fmt.Fprintln(dockerCli.Err(), sterr.Status) @@ -286,7 +289,7 @@ func tryPluginRun(dockerCli command.Cli, cmd *cobra.Command, subcommand string, } //nolint:gocyclo -func runDocker(dockerCli *command.DockerCli) error { +func runDocker(ctx context.Context, dockerCli *command.DockerCli) error { tcmd := newDockerCommand(dockerCli) cmd, args, err := tcmd.HandleGlobalFlags() @@ -298,6 +301,11 @@ func runDocker(dockerCli *command.DockerCli) error { return err } + mp := dockerCli.MeterProvider(ctx) + defer mp.Shutdown(ctx) + otel.SetMeterProvider(mp) + command.InstrumentCobraCommands(cmd, mp) + var envs []string args, os.Args, envs, err = processAliases(dockerCli, cmd, args, os.Args) if err != nil {