When shutting down the OTel providers have a ten second timeout. (#3199)

I noticed a misconfigured metrics URL would prevent the process
from quiting because it was trying to flush metrics forever.
This commit is contained in:
Dave Protasowski 2025-06-30 12:58:52 -04:00 committed by GitHub
parent 8481e7eef7
commit 434d22145d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 4 deletions

View File

@ -278,12 +278,13 @@ func MainWithConfig(ctx context.Context, component string, cfg *rest.Config, cto
mp, tp := SetupObservabilityOrDie(ctx, component, logger, pprof)
defer func() {
if err := mp.Shutdown(context.Background()); err != nil {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := mp.Shutdown(ctx); err != nil {
logger.Errorw("Error flushing metrics", zap.Error(err))
}
}()
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
if err := tp.Shutdown(ctx); err != nil {
logger.Errorw("Error flushing traces", zap.Error(err))
}
}()