telemetry: pass otel errors to the otel handler for shutdown and force flush

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg 2024-09-17 10:47:04 -05:00
parent a4619f3676
commit b1956f5073
No known key found for this signature in database
GPG Key ID: 6603D4B96394F6B1
2 changed files with 7 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/docker/cli/cli/version" "github.com/docker/cli/cli/version"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
) )
@ -94,7 +95,9 @@ func startCobraCommandTimer(mp metric.MeterProvider, attrs []attribute.KeyValue)
metric.WithAttributes(cmdStatusAttrs...), metric.WithAttributes(cmdStatusAttrs...),
) )
if mp, ok := mp.(MeterProvider); ok { if mp, ok := mp.(MeterProvider); ok {
mp.ForceFlush(ctx) if err := mp.ForceFlush(ctx); err != nil {
otel.Handle(err)
}
} }
} }
} }

View File

@ -358,7 +358,9 @@ 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 mp.Shutdown(ctx) if err := mp.Shutdown(ctx); err != nil {
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")
} }