Allow count_exceptions to add the error type as a label
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
Counter.count_exceptions と context_managers.ExceptionCounter から始め、次に with メソッドが例外の型とラベルをどのように処理するかを追跡します。既存の呼び出しと動作を維持したままエラーラベルを追加する方法を定義し、後方互換性のテストによって、要求されたエンドポイントと例外ラベルのユースケースを検証します。
索引モデルが 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時間
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 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 ·