Make the aiohttp-based SocketModeClient's debug logging more consistent with the built-in one (#1122)#1134
Conversation
…nt with the built-in one
| break | ||
| try: | ||
| message: WSMessage = await session.receive() | ||
| if self.trace_enabled and self.logger.level <= logging.DEBUG: |
There was a problem hiding this comment.
The main purpose of this PR is to remove trace_enabled check here. In the built-in client, message data logging does not require trace_enabled. This change makes the behavior more consistent.
| f" ({session_id})" | ||
| ) | ||
| self.logger.debug(log_message) | ||
| if self.trace_enabled and self.logger.level <= logging.DEBUG: |
There was a problem hiding this comment.
This debug logging is mainly for this SDK maintainers. We can disable this for most developers. That's why I added trace_enabled here.
| f"extra: {message.extra}, " | ||
| f"session: {session_id})" | ||
| # just in case, checking if the value is not None | ||
| if message is not None: |
There was a problem hiding this comment.
According to the type hint provided by aiohttp, we can assume the data cannot be None but we should check if it's not None, just in case (the behavior can be changed on the aiohttp library side in the future). In this PR, I've moved this check to cover the debug logging parts as well.
| and not await self.is_ping_pong_failing() | ||
| ) | ||
| if connected is False and self.logger.level <= logging.DEBUG: | ||
| if self.logger.level <= logging.DEBUG and connected is False: |
There was a problem hiding this comment.
This one and the following changes are minor improvements for readability
Codecov Report
@@ Coverage Diff @@
## main #1134 +/- ##
==========================================
- Coverage 86.62% 86.58% -0.04%
==========================================
Files 110 110
Lines 10749 10750 +1
==========================================
- Hits 9311 9308 -3
- Misses 1438 1442 +4
Continue to review full report at Codecov.
|
| # The logging here is for detailed investigation on potential issues in this client. | ||
| # If you don't see this log for a while, it means that | ||
| # this receive_messages execution is no longer working for some reason. | ||
| counter_for_logging = ( |
There was a problem hiding this comment.
I usually try to avoid the modulo operator (for performance reasons, unless the modulo operator can be a power of 2). In this case, it would be easy to avoid it, and possibly a bit clearer, by doing:
counter_for_logging += 1
if counter_for_logging >= logging_interval:
...
counter_for_logging = 0
There was a problem hiding this comment.
yeah, this sounds better
| ) % logging_interval | ||
| if counter_for_logging == 0: | ||
| log_message = ( | ||
| f"{logging_interval} session verification executed after the previous same log" |
There was a problem hiding this comment.
As a Bolt user, this message is still unclear to me. 😐
I think what it's trying to say might be something like this:
Checkpoint: 100 session verification messages received (session={session_id})
One thing I was wondering if there would be a value in not resetting the counter_for_logging variable, (which means my previous comment about avoiding modulo would need to ignored, since we'd need to check it to log this message every logging_interval times):
Checkpoint: Session verification message received (count={counter_for_logging} session={session_id})
This would have the benefit of providing log-insight in to how many messages have been processed since the Bolt application started since the counter would accumulate instead of being reset to 0 and always simply logging the logging_interval.
There was a problem hiding this comment.
Session verification message received
This suggested log message may not be accurate. In this method, all we do is just to monitor the current session is active. No communication with the server-side is involved here (ping-pong comms are done by aiohttp internals but it's not in this method).
Also, the intention of logging here is to periodically print some logs to tell the connection is alive even when the connection has not been receiving any incoming requests from Slack for a while. For this reason, I would like to avoid accumulating the count, which wont' be used for any purposes.
To make the log message clearer, I may want to revise it like:
monitor_current_session method has verified the session is active (session: {session_id}, logging interval: {logging_interval})
There was a problem hiding this comment.
Thanks for taking the time to write a detailed explanation, @seratch. Your proposed wording sounds good to me, and is an improvement (in my opinion) over the original message. (Having the {logging_interval} at the beginning didn't make sense to me until I checked the code to see what it was indicating.)
| # this receive_messages execution is no longer working for some reason. | ||
| if self.trace_enabled and counter_for_logging == 0: | ||
| log_message = ( | ||
| f"{logging_interval} WebSocket messages received " |
There was a problem hiding this comment.
Similarly here, if my understanding of this message is correct, I would probably phrase it like what I suggested above:
Checkpoint: WebSocket message received (count={counter_for_logging} session={session_id})
There was a problem hiding this comment.
I would like to avoid accumulating the number to avoid overflow errors in ultimate situations (say, a very busy app running for years without restart), just in case. Perhaps, we can say like this instead:
The receive_messages method has been working without any issues (session: {session_id}, logging interval: {logging_interval})
There was a problem hiding this comment.
OK. I'd suggest removing the leading "The" at beginning for consistency with the earlier, similar message.
| # The logging here is for detailed investigation on potential issues in this client. | ||
| # If you don't see this log for a while, it means that | ||
| # this receive_messages execution is no longer working for some reason. | ||
| counter_for_logging = ( |
There was a problem hiding this comment.
yeah, this sounds better
| ) % logging_interval | ||
| if counter_for_logging == 0: | ||
| log_message = ( | ||
| f"{logging_interval} session verification executed after the previous same log" |
There was a problem hiding this comment.
Session verification message received
This suggested log message may not be accurate. In this method, all we do is just to monitor the current session is active. No communication with the server-side is involved here (ping-pong comms are done by aiohttp internals but it's not in this method).
Also, the intention of logging here is to periodically print some logs to tell the connection is alive even when the connection has not been receiving any incoming requests from Slack for a while. For this reason, I would like to avoid accumulating the count, which wont' be used for any purposes.
To make the log message clearer, I may want to revise it like:
monitor_current_session method has verified the session is active (session: {session_id}, logging interval: {logging_interval})
| # this receive_messages execution is no longer working for some reason. | ||
| if self.trace_enabled and counter_for_logging == 0: | ||
| log_message = ( | ||
| f"{logging_interval} WebSocket messages received " |
There was a problem hiding this comment.
I would like to avoid accumulating the number to avoid overflow errors in ultimate situations (say, a very busy app running for years without restart), just in case. Perhaps, we can say like this instead:
The receive_messages method has been working without any issues (session: {session_id}, logging interval: {logging_interval})
Summary
This pull request fixes #1122 by improving the internals of the AIOHTTP-based Socket Mode client to be more consistent with the built-in client. Will add some context in line comments.
cc @eddyg
Category (place an
xin each of the[ ])/docs-src(Documents, have you run./scripts/docs.sh?)/docs-src-v2(Documents, have you run./scripts/docs-v2.sh?)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements (place an
xin each[ ])python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.