Use funcs on DockerCli to return Meter/TracerProviders, not initialize them. Initialize them during DockerCli struct init

Signed-off-by: Christopher Petito <chrisjpetito@gmail.com>
This commit is contained in:
Christopher Petito
2024-05-14 15:23:49 +00:00
parent 6c70360c79
commit 02537eac59
3 changed files with 44 additions and 23 deletions

View File

@ -308,9 +308,13 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
return err
}
mp := dockerCli.MeterProvider(ctx)
defer mp.Shutdown(ctx)
otel.SetMeterProvider(mp)
mp := dockerCli.MeterProvider()
if mp, ok := mp.(command.MeterProvider); ok {
defer mp.Shutdown(ctx)
} else {
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
}
dockerCli.InstrumentCobraCommands(cmd, mp)
var envs []string