-
Notifications
You must be signed in to change notification settings - Fork 428
Add log spans using thread local storage in tests #4287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
👋 Thanks for assigning @TheBlueMatt as a reviewer! |
38d439b to
5d2f39f
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4287 +/- ##
==========================================
- Coverage 86.61% 86.61% -0.01%
==========================================
Files 158 158
Lines 102730 102801 +71
Branches 102730 102801 +71
==========================================
+ Hits 88984 89045 +61
- Misses 11328 11338 +10
Partials 2418 2418
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1355c20 to
c3714c6
Compare
14f583e to
aedfe0a
Compare
|
Rebased and fixed a The problem was that Fixed by making |
|
Taking this out of draft as I'm committed to adding span support, but putting it on hold while an alternative approach is being investigated: using proc-macros to transparently augment every method with an implicit logger parameter, which would allow passing the span stack through that invisible parameter instead of relying on TLS. |
d84cd91 to
ee9b3bb
Compare
|
🔔 1st Reminder Hey @jkczyz! This PR has been waiting for your review. |
aba1a33 to
e119381
Compare
Introduces LoggerScope, a RAII guard that pushes span names onto a thread-local stack. In test builds with std, log messages are prefixed with the current span chain (e.g., "[outer->inner]") for easier debugging. Includes: - LoggerScope struct with automatic cleanup on drop - #[log_scope] proc macro to annotate functions with a logging context - test_scope! macro for manual scope changes within long test functions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Updated PR to be test-only. |
|
🔔 2nd Reminder Hey @TheBlueMatt! This PR has been waiting for your review. |
|
Need to decide on what level the spans are most helpful, where to apply #[log_scope] in main. Aside from what devs may add ad-hoc during testing. |
TheBlueMatt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to wait until we decide on #4322 since we'll want to re-use the proc-macro from there if we move forward. I guess they could move forward separately and just merge the macros on whichever lands second.
| /// [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum | ||
| /// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee | ||
| /// [`SendShutdown`]: MessageSendEvent::SendShutdown | ||
| #[log_scope] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use a single proc macro that also scopes sub-functions? If this is for tests presumably that's more useful and also less clutter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure indeed if we want to manually decide what useful spans are, or we can simply auto-annotate all pub fns, and do a few more perhaps manually if they are called frequently in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, kinda up to you given you have the most experience with using it, I suppose. Definitely we should automate pub fns, but up to you if you want to automate all fns or make it explicit. ISTM I'm always trying to do a full trace including non-public fns, but if you have a different experience alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit worried about presentation. Full trace might become a pretty long log line
This is a stripped-down version of #4223 where only the spans are stored in thread local storage. This is a test-only change - the span functionality is compiled out in non-test builds, so there is no impact on production code or no-std users.
Example log output:
std-spans.log