Skip to content

Commit

Permalink
telemetry: pass otel errors to the otel handler for shutdown and forc…
Browse files Browse the repository at this point in the history
…e flush

Signed-off-by: Jonathan A. Sternberg <[email protected]>
(cherry picked from commit b1956f5)
Signed-off-by: Laura Brehm <[email protected]>
  • Loading branch information
jsternberg authored and laurazard committed Sep 18, 2024
1 parent 58a14cc commit 4b5a196
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cli/command/telemetry_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 4b5a196

Please sign in to comment.