Skip to content

refactor(dash-spv): make logging a built-in event handler#745

Open
xdustinface wants to merge 1 commit intov0.42-devfrom
refactor/builtin-logging-event-handler
Open

refactor(dash-spv): make logging a built-in event handler#745
xdustinface wants to merge 1 commit intov0.42-devfrom
refactor/builtin-logging-event-handler

Conversation

@xdustinface
Copy link
Copy Markdown
Collaborator

@xdustinface xdustinface commented May 8, 2026

Move LoggingEventHandler out of the CLI binary and into dash-spv itself, then have DashSpvClient::new prepend it to the consumer-supplied handler list. Every consumer (CLI, FFI, integration tests, future embedders) now gets event log output for free as soon as a tracing subscriber is installed, instead of each one re-implementing the same bridge.

The handler is pub(crate) since consumers never need to construct or reference it. Per-event silencing is available through the standard tracing target filter dash_spv::client::event_handler=warn, so no opt-out flag is needed.

Summary by CodeRabbit

  • Refactor

    • Event logging is now built-in and automatically enabled for all clients, eliminating the need for manual logging configuration.
  • Tests

    • Added test coverage to verify automatic event handler attachment during client initialization.

Move `LoggingEventHandler` out of the CLI binary and into `dash-spv` itself, then have `DashSpvClient::new` prepend it to the consumer-supplied handler list. Every consumer (CLI, FFI, integration tests, future embedders) now gets event log output for free as soon as a `tracing` subscriber is installed, instead of each one re-implementing the same bridge.

The handler is `pub(crate)` since consumers never need to construct or reference it. Per-event silencing is available through the standard `tracing` target filter `dash_spv::client::event_handler=warn`, so no opt-out flag is needed.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb91d94b-341b-44a2-92f9-505290ba1613

📥 Commits

Reviewing files that changed from the base of the PR and between 49c8c6d and 96e95de.

📒 Files selected for processing (4)
  • dash-spv/src/client/event_handler.rs
  • dash-spv/src/client/lifecycle.rs
  • dash-spv/src/client/mod.rs
  • dash-spv/src/main.rs

📝 Walkthrough

Walkthrough

LoggingEventHandler is introduced as a built-in, crate-private handler in the event_handler module and automatically injected into every DashSpvClient during construction. The CLI removes its own redundant logging handler implementation and relies on this built-in instead, simplifying main.rs. A test verifies single handler auto-attachment.

Changes

Built-in Logging Handler Integration

Layer / File(s) Summary
Event Handler Implementation
dash-spv/src/client/event_handler.rs
LoggingEventHandler struct implements EventHandler trait with overrides for on_sync_event, on_network_event, on_progress, on_wallet_event, and on_error; all events log via tracing at info or error level.
Client Auto-Injection
dash-spv/src/client/lifecycle.rs
DashSpvClient::new imports LoggingEventHandler and prepends it to the caller-provided event_handlers list, ensuring the built-in handler is always present.
Test Coverage
dash-spv/src/client/mod.rs
New #[tokio::test] client_attaches_builtin_logging_handler verifies that DashSpvClient constructor auto-attaches exactly one built-in handler.
CLI Simplification
dash-spv/src/main.rs
Removes local LoggingEventHandler implementation, drops event-related imports, and updates DashSpvClient::new to pass empty Vec::new() for event handlers since the client now provides logging built-in.

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A handler springs forth from the client's own fold,
No duplication, the logging is bold!
CLI now sleek, one less task to maintain,
Events trace smoothly through tracing's domain.
Built-in and clean, the refactor's refrain! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor(dash-spv): make logging a built-in event handler' clearly and specifically describes the main change: moving the LoggingEventHandler into the dash-spv crate and making it a built-in handler automatically injected during client construction.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/builtin-logging-event-handler

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 70.00000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.63%. Comparing base (49c8c6d) to head (96e95de).

Files with missing lines Patch % Lines
dash-spv/src/main.rs 0.00% 12 Missing ⚠️
dash-spv/src/client/event_handler.rs 80.00% 3 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #745      +/-   ##
=============================================
+ Coverage      71.31%   71.63%   +0.31%     
=============================================
  Files            321      321              
  Lines          70339    70359      +20     
=============================================
+ Hits           50160    50399     +239     
+ Misses         20179    19960     -219     
Flag Coverage Δ
core 76.68% <ø> (ø)
ffi 47.40% <ø> (+2.42%) ⬆️
rpc 20.00% <ø> (ø)
spv 87.50% <70.00%> (-0.01%) ⬇️
wallet 69.85% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/client/lifecycle.rs 67.67% <100.00%> (+0.66%) ⬆️
dash-spv/src/client/mod.rs 100.00% <100.00%> (ø)
dash-spv/src/client/event_handler.rs 95.95% <80.00%> (-0.79%) ⬇️
dash-spv/src/main.rs 0.00% <0.00%> (ø)

... and 22 files with indirect coverage changes

@github-actions github-actions Bot added the ready-for-review CodeRabbit has approved this PR label May 8, 2026
@xdustinface xdustinface requested review from ZocoLini May 9, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review CodeRabbit has approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant