Skip to content

fix: check the effective log level before formatting debug logs - #2083

Merged
WilliamBergamin merged 4 commits into
mainfrom
fix/logger-is-enabled-for
Nov 25, 2026
Merged

WilliamBergamin merged 4 commits into
mainfrom
fix/logger-is-enabled-for

Conversation

@WilliamBergamin

@WilliamBergamin WilliamBergamin commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request switches the logger.level <= logging.DEBUG guards to logger.isEnabledFor(logging.DEBUG), as socket_mode already does.

  • Cause: logger.level is 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 for logger.debug to drop them.
  • 29 guards around logger.debug now check the effective level. Output is unchanged; the formatting is skipped when debug is off.
  • The 17 A retry handler found lines 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 logs Going to retry the same request at 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.
  • Behavior change: SQLite3InstallationStore lookup 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 legacy slack package 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 on main and pass here:

  • test_sqlite3.py: with a dropped table, find_bot logs one WARNING with no exc_info by default, and an ERROR with the traceback when debug is on.
  • test_web_client_http_retry.py: with debug off, a WebClient call never calls logger.debug; A retry handler found is a DEBUG record; at INFO a 429 retry logs only Going to retry the same request.
  • test_async_web_client_http_retry.py: with debug off, an AsyncWebClient call never calls logger.debug; at INFO a 429 retry logs Going to retry the same request.

To check by hand: run a WebClient call with logging.basicConfig(level=logging.INFO) and confirm no Received the following response line is formatted (put a breakpoint on it), then with level=logging.DEBUG and confirm it logs.

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs (Documents)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I have signed the Salesforce CLA (required before your PR can be reviewed or merged).
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

🤖 Generated with Claude Code

`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

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.78%. Comparing base (ac428dd) to head (15363fd).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
slack_sdk/rtm_v2/__init__.py 0.00% 6 Missing ⚠️
...k_sdk/oauth/installation_store/sqlite3/__init__.py 25.00% 3 Missing ⚠️
slack_sdk/web/internal_utils.py 0.00% 2 Missing ⚠️
slack_sdk/web/base_client.py 90.90% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪞 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 🤔

Comment thread slack_sdk/web/base_client.py Resolved
retry_response: Optional[RetryHttpResponse] = None

if logger.level <= logging.DEBUG:
if logger.isEnabledFor(logging.DEBUG):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 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>
@WilliamBergamin WilliamBergamin self-assigned this Nov 25, 2026
@WilliamBergamin WilliamBergamin added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch web-client area:async scim-client audit-logs-client rtm-client oauth labels Nov 25, 2026
@WilliamBergamin WilliamBergamin added this to the 3.48.1 milestone Nov 25, 2026
@WilliamBergamin
WilliamBergamin marked this pull request as ready for review November 25, 2026 17:05
@WilliamBergamin
WilliamBergamin requested a review from a team as a code owner November 25, 2026 17:05

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 9e63343, thanks! Every retry path now gets the INFO line, and the new 429 tests make it clear.

Comment thread slack/web/base_client.py Outdated
body_params = convert_bool_to_0_or_1(body_params)

if self._logger.level <= logging.DEBUG:
if self._logger.isEnabledFor(logging.DEBUG):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in commit 9e63343, thanks! 🙇

…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 mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Thanks @WilliamBergamin, a Going to retry line on every path keeps 429s visible at INFO while the handler detail moves to debug.

@WilliamBergamin
WilliamBergamin enabled auto-merge (squash) November 25, 2026 18:12
@WilliamBergamin
WilliamBergamin merged commit 838e3e4 into main Nov 25, 2026
19 checks passed
@WilliamBergamin
WilliamBergamin deleted the fix/logger-is-enabled-for branch November 25, 2026 18:17

@cchensh cchensh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked at 15363fd6.

  • Guards: every level <= guard under slack_sdk/ now uses isEnabledFor. The legacy slack package 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 found now logs at DEBUG.
    • Every retry logs Going to retry the same request at INFO, now on the async, audit_logs and scim clients too.
    • sqlite3 store lookup and delete failures log at WARNING.
  • Adapters: a LoggerAdapter used to raise AttributeError on .level and 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: isEnabledFor caches its result, and assigning logger.level = logging.DEBUG directly doesn't clear that cache; only setLevel() does. Anyone who turns debug on that way at runtime won't get debug output. socket_mode already 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_enabled also passes on main. It guards against a regression rather than proving the fix.
  • Samples (optional): the bolt_adapter samples under integration_tests/samples/socket_mode/ still compare logger.level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:async audit-logs-client bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented oauth rtm-client scim-client semver:patch web-client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants