Repository navigation
fix: check the effective log level before formatting debug logs - #2083
Conversation
`logger.level <= logging.DEBUG` reads the logger's own level, which is NOTSET (0) on every default SDK logger, so the guard was always true. Switch to `isEnabledFor(logging.DEBUG)`, as socket_mode already does. - Debug guards now skip building request/response log strings when debug is off. - Guards around the INFO "A retry handler found" lines are dropped, keeping today's default output. - SQLite3InstallationStore logs lookup/delete failures at WARNING unless debug is on (traceback at ERROR), as intended and as the S3 store does. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2083 +/- ##
==========================================
+ Coverage 84.76% 84.78% +0.02%
==========================================
Files 118 118
Lines 14129 14142 +13
==========================================
+ Hits 11976 11990 +14
+ Misses 2153 2152 -1 ☔ View full report in Codecov by Harness. |
WilliamBergamin
left a comment
There was a problem hiding this comment.
🪞 Nice sweep: isEnabledFor matches socket_mode, and the parent-logger tests fail on main for exactly the right reason.
One suggestion on the retry lines, the rest are optional 🤔
| retry_response: Optional[RetryHttpResponse] = None | ||
|
|
||
| if logger.level <= logging.DEBUG: | ||
| if logger.isEnabledFor(logging.DEBUG): |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): Could the async WebClient get the same not-formatted-when-debug-is-off test? The new guard test only covers the sync client.
The retry handler line was gated for debug since #1084, next to an ungated info "Going to retry the same request", so keep the guard on the effective level and log it at debug across web, webhook, scim, and audit_logs. Tests now assert the line is a DEBUG record and is absent at INFO, and cover the async WebClient debug guard. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
mwbrooks
left a comment
There was a problem hiding this comment.
One question on rate-limit retry logging at INFO before I approve. The isEnabledFor sweep itself looks great.
| if self._logger.level <= logging.DEBUG: | ||
| self._logger.info( | ||
| if self._logger.isEnabledFor(logging.DEBUG): | ||
| self._logger.debug( |
There was a problem hiding this comment.
question (blocking): With the root at INFO, a 429 or 5xx retry now logs nothing, since Going to retry the same request only runs on the connection-error path here and the async clients have no INFO retry line at all. Rate-limit retries are the ones developers most want to see, so could we keep an INFO line on these paths (or note in the PR body that going quiet is intended)?
There was a problem hiding this comment.
Fixed in commit 9e63343, thanks! Every retry path now gets the INFO line, and the new 429 tests make it clear.
| body_params = convert_bool_to_0_or_1(body_params) | ||
|
|
||
| if self._logger.level <= logging.DEBUG: | ||
| if self._logger.isEnabledFor(logging.DEBUG): |
There was a problem hiding this comment.
suggestion (non-blocking): AGENTS.md asks us not to modify the legacy slack/ package, so I'd drop the four slack/ edits unless there's a reason to fix them there too.
…ched Rate-limit and server-error retries were silent at INFO once the handler detail moved to DEBUG. Every retry path now logs "Going to retry the same request" at INFO, matching the existing connection-error path. The legacy slack/ package is restored to main, since it is in maintenance mode. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
mwbrooks
left a comment
There was a problem hiding this comment.
✅ Thanks @WilliamBergamin, a Going to retry line on every path keeps 429s visible at INFO while the handler detail moves to debug.
cchensh
left a comment
There was a problem hiding this comment.
Checked at 15363fd6.
- Guards: every
level <=guard underslack_sdk/now usesisEnabledFor. The legacyslackpackage keeps its old guards (9e63343), which keeps that deprecated package unchanged. - Side effects: in each guard I checked, the variables it assigns (
headers,body,headers_for_logging) aren't read afterward. So the only behaviour changes are the documented ones:A retry handler foundnow logs at DEBUG.- Every retry logs
Going to retry the same requestat INFO, now on the async, audit_logs and scim clients too. - sqlite3 store lookup and delete failures log at WARNING.
- Adapters: a
LoggerAdapterused to raiseAttributeErroron.leveland now works.
Nits:
- Release notes: worth calling out the sqlite3 ERROR-with-traceback → WARNING change (anyone alerting on those ERROR records loses them) and the retry-handler line moving from INFO to DEBUG.
- Level cache:
isEnabledForcaches its result, and assigninglogger.level = logging.DEBUGdirectly doesn't clear that cache; onlysetLevel()does. Anyone who turns debug on that way at runtime won't get debug output.socket_modealready behaves this way, so a line in the docs would cover it. - S3 comparison: "what the S3 store does" only holds for the default path. With debug on, sqlite3 still calls
logger.exception, while S3 always logs WARNING. - Test:
test_lookup_failure_logs_the_traceback_when_debug_is_enabledalso passes onmain. It guards against a regression rather than proving the fix. - Samples (optional): the bolt_adapter samples under
integration_tests/samples/socket_mode/still comparelogger.level.
Summary
This pull request switches the
logger.level <= logging.DEBUGguards tologger.isEnabledFor(logging.DEBUG), assocket_modealready does.logger.levelis the logger's own level,NOTSET(0) on every default SDK logger, so the guard was always true. Each call built its debug strings (params, headers, full response body) only forlogger.debugto drop them.logger.debugnow check the effective level. Output is unchanged; the formatting is skipped when debug is off.A retry handler foundlines keep their guard, now on the effective level, and log at DEBUG, as Fix #887 Enable automatic retry by a handy way #1084 intended. Every retry path, sync and async, now logsGoing to retry the same requestat INFO, which before only the sync connection-error path did. So 429 and 5xx retries stay visible at INFO, and the handler detail needs DEBUG.SQLite3InstallationStorelookup or delete failures now log at WARNING without a traceback unless debug is on, which is what the branch intended and what the S3 store does. Before, they always logged at ERROR with a traceback.Covers
web,webhook,audit_logs,scim,rtm,rtm_v2, and the sqlite3 installation store. The legacyslackpackage is untouched. No generated code changes.Testing
New tests set the level on a parent logger so the SDK logger stays
NOTSET, the same pattern as #1965. They fail onmainand pass here:test_sqlite3.py: with a dropped table,find_botlogs one WARNING with noexc_infoby default, and an ERROR with the traceback when debug is on.test_web_client_http_retry.py: with debug off, aWebClientcall never callslogger.debug;A retry handler foundis a DEBUG record; at INFO a 429 retry logs onlyGoing to retry the same request.test_async_web_client_http_retry.py: with debug off, anAsyncWebClientcall never callslogger.debug; at INFO a 429 retry logsGoing to retry the same request.To check by hand: run a
WebClientcall withlogging.basicConfig(level=logging.INFO)and confirm noReceived the following responseline is formatted (put a breakpoint on it), then withlevel=logging.DEBUGand confirm it logs.Category
/docs(Documents)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.🤖 Generated with Claude Code