Allow count_exceptions to add the error type as a label
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- observability-sre
Hướng nghiên cứu
Bắt đầu với Counter.count_exceptions và context_managers.ExceptionCounter, sau đó theo dõi cách phương thức with xử lý các kiểu ngoại lệ và nhãn. Xác định cách thêm nhãn lỗi mà vẫn giữ nguyên các lời gọi và hành vi hiện có, đồng thời kiểm tra endpoint được yêu cầu và trường hợp sử dụng nhãn ngoại lệ bằng các bài kiểm thử khả năng tương thích ngược.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 4.4k
- Fork
- 876
- Merge trung bình
- 8 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của prometheus/client_python
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
prometheus/client_python#1177 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
prometheus/client_python#1210 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 58/100
prometheus/client_python#1199 · 1 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
prometheus/client_python#1176 ·
-
WSL and MultiProcessCollector Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 52/100
prometheus/client_python#1126 · 2 bình luận ·
Tất cả issue của prometheus/client_python
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
stephrobert/dsoxlab#238 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
sublimehq/package_control#1780 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
nwg-piotr/nwg-displays#145 ·