66
77import aio_pika
88import aiormq
9+ from common_library .logging .logging_errors import create_troubleshooting_log_kwargs
910from settings_library .rabbit import RabbitSettings
1011
1112from ..logging_utils import log_catch
@@ -29,33 +30,49 @@ def _connection_close_callback(
2930 exc : BaseException | None ,
3031 ) -> None :
3132 if exc :
32- if isinstance (exc , asyncio .CancelledError ):
33- _logger .info ("Rabbit connection cancelled" )
34- elif isinstance (exc , aiormq .exceptions .ConnectionClosed ):
35- _logger .info ("Rabbit connection closed: %s" , exc )
33+ if isinstance (
34+ exc , asyncio .CancelledError | aiormq .exceptions .ConnectionClosed
35+ ):
36+ _logger .info (
37+ ** create_troubleshooting_log_kwargs (
38+ "RabbitMQ connection closed" ,
39+ error = exc ,
40+ error_context = {"sender" : sender },
41+ )
42+ )
3643 else :
3744 _logger .error (
38- "Rabbit connection closed with exception from %s:%s" ,
39- type (exc ),
40- exc ,
45+ ** create_troubleshooting_log_kwargs (
46+ "RabbitMQ connection closed with unexpected error" ,
47+ error = exc ,
48+ error_context = {"sender" : sender },
49+ )
4150 )
4251 self ._healthy_state = False
4352
4453 def _channel_close_callback (
4554 self ,
46- sender : Any , # pylint: disable=unused-argument # noqa: ARG002
55+ sender : Any ,
4756 exc : BaseException | None ,
4857 ) -> None :
4958 if exc :
50- if isinstance (exc , asyncio .CancelledError ):
51- _logger .info ("Rabbit channel cancelled" )
52- elif isinstance (exc , aiormq .exceptions .ChannelClosed ):
53- _logger .info ("Rabbit channel closed" )
59+ if isinstance (
60+ exc , asyncio .CancelledError | aiormq .exceptions .ChannelClosed
61+ ):
62+ _logger .info (
63+ ** create_troubleshooting_log_kwargs (
64+ "RabbitMQ channel closed" ,
65+ error = exc ,
66+ error_context = {"sender" : sender },
67+ )
68+ )
5469 else :
5570 _logger .error (
56- "Rabbit channel closed with exception from %s:%s" ,
57- type (exc ),
58- exc ,
71+ ** create_troubleshooting_log_kwargs (
72+ "RabbitMQ channel closed with unexpected error" ,
73+ error = exc ,
74+ error_context = {"sender" : sender },
75+ )
5976 )
6077 self ._healthy_state = False
6178
0 commit comments