Allow count_exceptions to add the error type as a label
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- python
研究方向
從 Counter.count_exceptions 和 context_managers.ExceptionCounter 開始,接著追蹤 with 方法如何處理例外類型和標籤。定義如何在保留現有呼叫和行為的同時新增錯誤標籤,並透過向後相容性測試驗證所要求的 endpoint 和例外標籤使用情境。
由索引模型根據 Issue 內容生成。
描述
I'd like count_exceptions to add the error type as a label so I can track what errors are occurring against what endpoints for my application.
I'd like to do this via the with method.
from prometheus_client import Counter
ERRORS = Counter(
'http_request_errors_count',
'Count of exceptions that happen during an HTTP request',
['method', 'endpoint', 'error']
)
async def error_middleware(request, handler):
try:
with ERRORS.count_exceptions(request.method, request.path):
return await handler(request)
except SomeHTTPException as e:
...
To do this I've created my own custom Counter classes.
from prometheus_client import Counter, context_managers
class CustomExceptionCounter(context_managers.ExceptionCounter):
def __init__(self, counter, exception, *labels):
self._counter = counter
self._exception = exception
self._labels = labels
def __exit__(self, typ, value, traceback):
if isinstance(value, self._exception):
self._counter.labels(*(*self._labels, typ.__name__)).inc() # Append exception's name as a label
class CustomCounter(Counter):
def count_exceptions(self, *labels, exception=Exception):
return CustomExceptionCounter(self, exception, *labels)
ERRORS = CustomCounter(
'http_request_errors_count',
'Count of CancelledError exceptions',
['method', 'endpoint', 'error']
)
I think there is a general solution that's backward compatible, I've just not figured it out. Is this something you'd support? I'd be happy to submit a PR if I can figure out how to make this backward compatible.
- 主要語言
- Python
- 星號
- 4.4k
- 分支
- 876
- 平均合併
- 8 天 4 小時
- 30 天內合併 PR
- 1
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
prometheus/client_python 的其他 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 70/100
prometheus/client_python#1177 · 1 則留言 ·
-
難度 4/5 3-5 天 新手友好度 45/100
prometheus/client_python#1210 ·
-
難度 2/5 1-3 小時 新手友好度 58/100
prometheus/client_python#1199 · 1 個 reaction ·
-
難度 5/5 一週以上 新手友好度 35/100
prometheus/client_python#1176 ·
-
難度 1/5 1-3 小時 新手友好度 52/100
prometheus/client_python#1126 · 2 則留言 ·
查看 prometheus/client_python 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
stephrobert/dsoxlab#238 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 75/100
sublimehq/package_control#1780 ·
-
難度 2/5 1-3 小時 新手友好度 65/100
-
難度 2/5 1-3 小時 新手友好度 70/100
nwg-piotr/nwg-displays#145 ·