Getting error on endpoint "A server error occurred. Please contact the administrator."
New to the Prometheus client on Python and implementing an endpoint for an application.
Not seeing any obvious errors but don't have any debugging log available (yet) for the application but wondering if anyone else has observed this and could point to potential causes.
I do not believe that is an error that would come from this client, it is likely an error from your application/how you expose this client. Do you have a code sample to show what you are trying to do/reproduce this issue?
It looks like this can happen if a custom collector raises an unhandled exception. The following code snippet causes the error to occur when browsing to the Prometheus client endpoint.
import time
from prometheus_client import start_http_server
from prometheus_client.core import GaugeMetricFamily, REGISTRY
class CustomCollector(object):
def __init__(self):
self._started = False
def collect(self):
if self._started:
raise Exception('whoops')
self._started = True
yield GaugeMetricFamily('my_gauge', 'Help text', value=7)
REGISTRY.register(CustomCollector())
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(8000)
while True:
time.sleep(1)
The error itself originates in WSGI. Perhaps the library should be catching exceptions when attempting to collect?
In that example it looks like the behavior I expect. I am seeing the "A server error occurred. Please contact the administrator." error on the page, and the exception is printed to stdout so that someone can fix it. The server keeps running so future requests can succeed.
We could propagate the exception to the page as well, but that could also leak information so the generic message might be better.
Apologies for not returning to this one - This was an app error in the end.