Skip to content

Commit

Permalink
Merge pull request #5448 from laurazard/backport-otel-shutdown-errors
Browse files Browse the repository at this point in the history
[27.x backport] telemetry: handle otel errors on shutdown
  • Loading branch information
thaJeztah committed Sep 18, 2024
2 parents ddf8f23 + 4b5a196 commit e4dc9d2
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 e4dc9d2

Please sign in to comment.