client_golang
client_golang copied to clipboard
Registry.Gather should turn panics into errors
This code:
https://github.com/prometheus/client_golang/blob/9358c16714047a9913e13285f8d0f8b21e2c80b1/prometheus/registry.go#L452-L456
will end the whole program if the collector panics, since it is run on a background goroutine. This may be an unpleasant lesson.
As a comparison, the net/http package handles panics anywhere in the serving code, although the author says they should have made this opt-in.
I note that ErrGroup added then removed this feature; reading the thread I understand that the reasons were (1) it could take a long time to reveal the error and (2) the stack trace was lost. Gather can fail immediately on panic, and can supply the stack trace in the error it returns.