From 4b5a196fee11e82e15d2c2c36ba2883e5717fde3 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Tue, 17 Sep 2024 10:47:04 -0500 Subject: [PATCH] telemetry: pass otel errors to the otel handler for shutdown and force flush Signed-off-by: Jonathan A. Sternberg (cherry picked from commit b1956f50734612ee175f991e4847a5312e5e455f) Signed-off-by: Laura Brehm --- cli/command/telemetry_utils.go | 5 ++++- cmd/docker/docker.go | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/command/telemetry_utils.go b/cli/command/telemetry_utils.go index 905f8a4614..680415b637 100644 --- a/cli/command/telemetry_utils.go +++ b/cli/command/telemetry_utils.go @@ -9,6 +9,7 @@ import ( "github.com/docker/cli/cli/version" "github.com/pkg/errors" "github.com/spf13/cobra" + "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" ) @@ -94,7 +95,9 @@ func startCobraCommandTimer(mp metric.MeterProvider, attrs []attribute.KeyValue) metric.WithAttributes(cmdStatusAttrs...), ) if mp, ok := mp.(MeterProvider); ok { - mp.ForceFlush(ctx) + if err := mp.ForceFlush(ctx); err != nil { + otel.Handle(err) + } } } } diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 6e28a99ebc..a8ef0cd63d 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -360,7 +360,9 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error { mp := dockerCli.MeterProvider() if mp, ok := mp.(command.MeterProvider); ok { - defer mp.Shutdown(ctx) + if err := mp.Shutdown(ctx); err != nil { + otel.Handle(err) + } } else { fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed") }