collector: add stack trace, if collector panics (#1650)

This commit is contained in:
Jan-Otto Kröpke
2024-09-28 15:57:56 +02:00
committed by GitHub
parent 01e809315c
commit a1defadf1e
2 changed files with 26 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import (
"context"
"fmt"
"log/slog"
"runtime/debug"
"sync"
"sync/atomic"
"time"
@@ -187,6 +188,7 @@ func (p *Prometheus) execute(name string, c Collector, scrapeCtx *types.ScrapeCo
if r := recover(); r != nil {
p.logger.Error("panic in collector "+name,
slog.Any("panic", r),
slog.Any("stack", string(debug.Stack())),
)
}
}()