From 460f1becc5c330e8df1f79857a089a9808132de6 Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Fri, 20 Sep 2024 01:29:19 +0100 Subject: [PATCH] telemetry: fix early meterprovider shutdown In 4b5a196fee11e82e15d2c2c36ba2883e5717fde3, we changed the CLI global meter provider shutdown in order to handle any error returned by the metric export. Unfortunately, we dropped a `defer` during the fix, which causes the meter provider to be immediately shutdown after being created and metrics to not be collected/exporter. Signed-off-by: Laura Brehm (cherry picked from commit 1355d7e9f850995834cdee93bc759ae58ff7aa3d) Signed-off-by: Laura Brehm --- cmd/docker/docker.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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") }