Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: HandlerException ingored #1928

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions faststream/prometheus/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence

from faststream import BaseMiddleware
from faststream.exceptions import IgnoredException
from faststream.prometheus.consts import (
PROCESSING_STATUS_BY_ACK_STATUS,
PROCESSING_STATUS_BY_HANDLER_EXCEPTION_MAP,
Expand Down Expand Up @@ -71,11 +72,13 @@ async def consume_scope(

except Exception as e:
err = e
self._metrics_manager.add_received_processed_message_exception(
exception_type=type(err).__name__,
broker=messaging_system,
handler=destination_name,
)

if not isinstance(err, IgnoredException):
self._metrics_manager.add_received_processed_message_exception(
exception_type=type(err).__name__,
broker=messaging_system,
handler=destination_name,
)
raise

finally:
Expand Down
14 changes: 12 additions & 2 deletions tests/prometheus/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from faststream import Context
from faststream.broker.message import AckStatus
from faststream.exceptions import RejectMessage
from faststream.exceptions import IgnoredException, RejectMessage
from faststream.prometheus.middleware import (
PROCESSING_STATUS_BY_ACK_STATUS,
PROCESSING_STATUS_BY_HANDLER_EXCEPTION_MAP,
Expand Down Expand Up @@ -54,6 +54,11 @@ def settings_provider_factory(self):
pytest.param(
AckStatus.rejected, None, id="rejected status without exception"
),
pytest.param(
AckStatus.acked,
IgnoredException,
id="acked status with ignore exception",
),
],
)
async def test_metrics(
Expand Down Expand Up @@ -176,7 +181,7 @@ def assert_consume_metrics(
),
]

if status == ProcessingStatus.error:
if exception_class and not issubclass(exception_class, IgnoredException):
assert (
metrics_manager.add_received_processed_message_exception.mock_calls
== [
Expand All @@ -187,6 +192,11 @@ def assert_consume_metrics(
),
]
)
else:
assert (
metrics_manager.add_received_processed_message_exception.mock_calls
== []
)

def assert_publish_metrics(self, metrics_manager: Any):
settings_provider = self.settings_provider_factory(None)
Expand Down
Loading