Initial otel impl using our utils

Signed-off-by: Christopher Petito <chrisjpetito@gmail.com>
This commit is contained in:
Christopher Petito 2024-03-28 16:23:01 +00:00
parent b6e2eca4b8
commit efd82e1e31
1 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@ -21,17 +22,19 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"go.opentelemetry.io/otel"
) )
func main() { func main() {
dockerCli, err := command.NewDockerCli() ctx := context.Background()
dockerCli, err := command.NewDockerCli(command.WithBaseContext(ctx))
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
os.Exit(1) os.Exit(1)
} }
logrus.SetOutput(dockerCli.Err()) 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, ok := err.(cli.StatusError); ok {
if sterr.Status != "" { if sterr.Status != "" {
fmt.Fprintln(dockerCli.Err(), sterr.Status) fmt.Fprintln(dockerCli.Err(), sterr.Status)
@ -286,7 +289,7 @@ func tryPluginRun(dockerCli command.Cli, cmd *cobra.Command, subcommand string,
} }
//nolint:gocyclo //nolint:gocyclo
func runDocker(dockerCli *command.DockerCli) error { func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
tcmd := newDockerCommand(dockerCli) tcmd := newDockerCommand(dockerCli)
cmd, args, err := tcmd.HandleGlobalFlags() cmd, args, err := tcmd.HandleGlobalFlags()
@ -298,6 +301,11 @@ func runDocker(dockerCli *command.DockerCli) error {
return err return err
} }
mp := dockerCli.MeterProvider(ctx)
defer mp.Shutdown(ctx)
otel.SetMeterProvider(mp)
command.InstrumentCobraCommands(cmd, mp)
var envs []string var envs []string
args, os.Args, envs, err = processAliases(dockerCli, cmd, args, os.Args) args, os.Args, envs, err = processAliases(dockerCli, cmd, args, os.Args)
if err != nil { if err != nil {