Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/jupyter_server/prometheus/log_functions.py: 67%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

3 statements  

1"""Log functions for prometheus""" 

2 

3from .metrics import HTTP_REQUEST_DURATION_SECONDS # type:ignore[unused-ignore] 

4 

5 

6def prometheus_log_method(handler): 

7 """ 

8 Tornado log handler for recording RED metrics. 

9 

10 We record the following metrics: 

11 Rate - the number of requests, per second, your services are serving. 

12 Errors - the number of failed requests per second. 

13 Duration - The amount of time each request takes expressed as a time interval. 

14 

15 We use a fully qualified name of the handler as a label, 

16 rather than every url path to reduce cardinality. 

17 

18 This function should be either the value of or called from a function 

19 that is the 'log_function' tornado setting. This makes it get called 

20 at the end of every request, allowing us to record the metrics we need. 

21 """ 

22 HTTP_REQUEST_DURATION_SECONDS.labels( 

23 method=handler.request.method, 

24 handler=f"{handler.__class__.__module__}.{type(handler).__name__}", 

25 status_code=handler.get_status(), 

26 ).observe(handler.request.request_time())