Skip to content

Add exception info to logger warnings for better debugging#307

Merged
tomquist merged 2 commits intodevelopfrom
claude/add-warning-stacktrace-C6AIo
Apr 6, 2026
Merged

Add exception info to logger warnings for better debugging#307
tomquist merged 2 commits intodevelopfrom
claude/add-warning-stacktrace-C6AIo

Conversation

@tomquist
Copy link
Copy Markdown
Owner

@tomquist tomquist commented Apr 6, 2026

Summary

Enhanced logging throughout the codebase by adding exc_info=True parameter to logger.warning() calls that handle exceptions. This ensures that full stack traces are included in warning logs, improving debuggability.

Key Changes

  • Added exc_info=True to _call_event_listener() exception handler to log full stack trace when event listener fails
  • Added exc_info=True to _call_before_send() exception handler to log full stack trace when before_send callback fails
  • Added exc_info=True to _handle_request() exception handler to log full stack trace when request handling fails

Implementation Details

These changes maintain backward compatibility while improving observability. When exc_info=True is passed to logger.warning(), Python's logging module automatically includes the full exception traceback in the log output, making it easier to diagnose issues in production environments without requiring additional error handling code.

https://claude.ai/code/session_01SGt3XARC6exgnu1jEnYiza

claude added 2 commits April 6, 2026 21:15
Pass exc_info=True so before_send, event_listener, and response-build
failures include the underlying traceback, making issues like #305
diagnosable.
Install a LogRecord filter in config/logger.py that, whenever a log
record of WARNING level or above is emitted while an exception is in
flight (sys.exc_info() is set) and no exc_info was passed explicitly,
attaches the active exception so the traceback is included. Call sites
that want to stay terse can opt out with exc_info=False; this is done
in the MQTT and MQTT Insights reconnect loops where the message alone
is enough.

Also pass exc_info=True explicitly at the most important catch-all
log sites (Shelly event listener, Home Assistant/HomeWizard WebSocket
loops, throttled powermeter fetch, Marstek auto-registration) so the
intent is obvious at the call site.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 6, 2026

Warning

Rate limit exceeded

@tomquist has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 47 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 5 minutes and 47 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00f89996-71b9-429b-b475-c5d645681141

📥 Commits

Reviewing files that changed from the base of the PR and between 5432f4a and dbe6840.

📒 Files selected for processing (10)
  • src/astrameter/config/logger.py
  • src/astrameter/config/logger_test.py
  • src/astrameter/ct002/ct002.py
  • src/astrameter/main.py
  • src/astrameter/mqtt_insights/service.py
  • src/astrameter/powermeter/homeassistant.py
  • src/astrameter/powermeter/homewizard.py
  • src/astrameter/powermeter/mqtt.py
  • src/astrameter/powermeter/throttling.py
  • src/astrameter/shelly/shelly.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/add-warning-stacktrace-C6AIo

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tomquist tomquist merged commit bf0503d into develop Apr 6, 2026
13 checks passed
@tomquist tomquist deleted the claude/add-warning-stacktrace-C6AIo branch April 6, 2026 21:33
tomquist pushed a commit that referenced this pull request Apr 19, 2026
Regrouped the flat bullet list into Breaking / Added / Changed / Fixed
subsections so readers can scan by change type. Each bullet is now a
standalone diff to main (no cross-references) and cites every PR that
contributed.

Added Breaking entries that were missing:
- CT002/CT003 ACTIVE_CONTROL default (smoothing + 15 W BALANCE_DEADBAND
  + saturation detection on by default)
- WAIT_FOR_NEXT_MESSAGE default True (affects Shelly emulation too, not
  just CT002/CT003)
- Async Powermeter base (out-of-tree subclasses must implement
  async get_powermeter_watts())

Added missing feature bullets: per-powermeter EMA smoothing/deadband
wrappers (#331), Hampel outlier filter (#334), MQTT BROKER_URI (#309),
exc_info on warnings (#307). Filled in previously-missing PR refs on
the rebrand, CT002/CT003, MQTT Insights, web config editor, PID
controller, and GIT_COMMIT_SHA bullets.

https://claude.ai/code/session_01BCVmemteVXNfoTQE4De2CU
tomquist added a commit that referenced this pull request Apr 19, 2026
* Restructure CHANGELOG Next section as Keep-a-Changelog diff to main

Regrouped the flat bullet list into Breaking / Added / Changed / Fixed
subsections so readers can scan by change type. Each bullet is now a
standalone diff to main (no cross-references) and cites every PR that
contributed.

Added Breaking entries that were missing:
- CT002/CT003 ACTIVE_CONTROL default (smoothing + 15 W BALANCE_DEADBAND
  + saturation detection on by default)
- WAIT_FOR_NEXT_MESSAGE default True (affects Shelly emulation too, not
  just CT002/CT003)
- Async Powermeter base (out-of-tree subclasses must implement
  async get_powermeter_watts())

Added missing feature bullets: per-powermeter EMA smoothing/deadband
wrappers (#331), Hampel outlier filter (#334), MQTT BROKER_URI (#309),
exc_info on warnings (#307). Filled in previously-missing PR refs on
the rebrand, CT002/CT003, MQTT Insights, web config editor, PID
controller, and GIT_COMMIT_SHA bullets.

https://claude.ai/code/session_01BCVmemteVXNfoTQE4De2CU

* Fold same-cycle fixes into their parent Added bullets

The Fixed / Changed bullets for CT002/CT003 saturation, efficiency-
rotation lockup, and the MQTT_INSIGHTS empty-config crash / HA mosquitto
availability check referenced features introduced in this same release
cycle, so they weren't a standalone diff against main. Merged those PR
refs into the CT002/CT003 and MQTT Insights Added bullets (the end
state, which is what a main-viewer cares about). Modbus UNIT_ID fix
stays in Fixed — Modbus existed on main.

https://claude.ai/code/session_01BCVmemteVXNfoTQE4De2CU

* Fold CT002/CT003 active-control defaults into Added bullet

The CT002/CT003 ACTIVE_CONTROL default is not a 'changed default' vs
main — CT002/CT003 don't exist on main, so the default is just part of
the new feature description. Moved the default-on behavior and
BALANCE_DEADBAND details into the CT002/CT003 Added bullet.

Also narrowed the WAIT_FOR_NEXT_MESSAGE Breaking bullet to just the
Shelly emulator (the real diff against main); the CT002/CT003 aspect
is implicit in the CT002/CT003 Added bullet.

Fixed a minor verb mismatch in Changed: 'Added battery activity
info logs' → 'Expanded Shelly emulation logs'.

https://claude.ai/code/session_01BCVmemteVXNfoTQE4De2CU

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants