telemetry: fix early meterprovider shutdown

In 4b5a196fee, 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 <laurabrehm@hey.com>
(cherry picked from commit 1355d7e9f8)
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
Laura Brehm 2024-09-20 01:29:19 +01:00
parent e85edf8556
commit 460f1becc5
No known key found for this signature in database
GPG Key ID: 08EC1B0491948487
1 changed files with 5 additions and 3 deletions

View File

@ -360,9 +360,11 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
mp := dockerCli.MeterProvider() mp := dockerCli.MeterProvider()
if mp, ok := mp.(command.MeterProvider); ok { if mp, ok := mp.(command.MeterProvider); ok {
defer func() {
if err := mp.Shutdown(ctx); err != nil { if err := mp.Shutdown(ctx); err != nil {
otel.Handle(err) otel.Handle(err)
} }
}()
} else { } else {
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed") fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
} }