diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index a8ef0cd63d..23faa17365 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -360,9 +360,11 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error { mp := dockerCli.MeterProvider() if mp, ok := mp.(command.MeterProvider); ok { - if err := mp.Shutdown(ctx); err != nil { - otel.Handle(err) - } + defer func() { + if err := mp.Shutdown(ctx); err != nil { + otel.Handle(err) + } + }() } else { fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed") }