Skip to content

feat: add granular tracing#140

Merged
chatton merged 5 commits intomainfrom
cian/add-granular-tracing
Feb 24, 2026
Merged

feat: add granular tracing#140
chatton merged 5 commits intomainfrom
cian/add-granular-tracing

Conversation

@chatton
Copy link
Contributor

@chatton chatton commented Feb 24, 2026

Description

Utilizing the #[instrument] macro to get more granular tracing. Added tests which verify the spans are being collected.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Refactoring

Related Issues

Fixes #137

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Testing

Additional Notes

Here's a sample of the spans putting it into one of our docker tests

  ┌──────────────────────┬───────┬───────┐
  │         Span         │ Count │  Avg  │
  ├──────────────────────┼───────┼───────┤
  │ storage worker       │ 2,448 │ 5.1ms │
  ├──────────────────────┼───────┼───────┤
  │ account worker       │ 2,448 │ 4.6ms │
  ├──────────────────────┼───────┼───────┤
  │ try_build            │ 354   │ 3.9ms │
  ├──────────────────────┼───────┼───────┤
  │ build_payload        │ 354   │ 3.8ms │
  ├──────────────────────┼───────┼───────┤
  │ execute_tx           │ 1,053 │ 925µs │
  ├──────────────────────┼───────┼───────┤
  │ validate_transaction │ 1,318 │ 41µs  │
  ├──────────────────────┼───────┼───────┤
  │ on_new_payload       │ 271   │ 4.4ms │
  ├──────────────────────┼───────┼───────┤
  │ execute_block        │ 272   │ 3.2ms │
  └──────────────────────┴───────┴───────┘

…xpool

Add structured tracing spans to the four key code paths:
- build_payload: per-block span with parent_hash, tx_count, gas_limit
- try_build: outer Engine API entry point with payload_id
- ensure_well_formed_payload: inbound payload validation with block_number
- validate_transaction: txpool validation with origin and tx_hash
- Per-transaction debug_span in the execution loop

Also cleans up log messages to use structured fields and lean on
span context instead of verbose prefixes.
Cover the remaining 4 #[instrument] call sites with SpanCollector-based
tests: execute_tx, ensure_well_formed_payload, try_build, and
validate_transaction.
@claude
Copy link

claude bot commented Feb 24, 2026

Claude finished @chatton's task —— View job


Code Review: Granular Tracing Implementation ✅

I've completed a comprehensive review of this PR that adds granular tracing to the ev-reth codebase. Overall, this is a well-implemented feature that adds valuable observability without compromising performance or security.

Todo List:

  • Read and analyze all changed files
  • Review code quality and Rust best practices
  • Check for potential bugs or issues
  • Evaluate performance considerations
  • Assess security concerns
  • Review test coverage and effectiveness
  • Provide comprehensive feedback and recommendations

Code Quality & Best Practices

Excellent implementation with proper Rust patterns:

  • Appropriate use of #[instrument] macro from the tracing crate
  • Consistent field naming (duration_ms, tx_count, payload_id, etc.)
  • Good use of tracing::field::Empty for delayed field recording
  • Proper span lifecycle management with tracing::Span::current().record()

Well-structured tracing architecture:

  • Strategic placement of instrumentation on critical paths
  • Clean separation between span creation and field recording
  • Consistent instrumentation patterns across all modules

Performance Considerations

Minimal overhead implementation:

  • Uses std::time::Instant::now() only when necessary
  • Lazy field evaluation prevents performance impact when tracing is disabled
  • Strategic field selection (hash, transaction count, gas metrics)
  • No blocking operations introduced

Efficient span management:

  • Proper use of span enter/exit patterns in builder.rs:152-158
  • Duration recording at span completion prevents timing inaccuracies

Security Assessment

No security concerns identified:

  • No exposure of sensitive data in trace fields
  • Appropriate use of display formatters (% vs ?) for different field types
  • No credential or private key exposure risks

Test Coverage

Comprehensive test strategy:

  • New test utility: test_utils.rs provides SpanCollector for validation
  • Field verification tests: All instrumented functions have corresponding tests
  • Integration coverage: Tests verify both span creation and field population
  • Specific test cases:
    • crates/node/src/builder.rs:247-317 - Tests build_payload span fields
    • crates/node/src/builder.rs:320-401 - Tests execute_tx span fields
    • crates/node/src/payload_service.rs:302-388 - Tests try_build span fields
    • crates/node/src/txpool.rs:769-798 - Tests validate_transaction span fields
    • crates/node/src/validator.rs:293-367 - Tests ensure_well_formed_payload span fields

🔍 Minor Issues & Suggestions

1. Bug in Balance Validation (crates/node/src/txpool.rs:436-444)

// Current code has logical issue:
let EvTxEnvelope::EvNode(tx) = consensus else {
    if sender_balance < *pooled.cost() {
        return Err(InvalidPoolTransactionError::Overdraft { cost: *pooled.cost(), balance: sender_balance });
    }
    return Ok(()); // Early return for non-EvNode transactions
};

Issue: The balance check for non-EvNode transactions occurs in the wrong branch. The failing test non_sponsored_evnode_rejects_insufficient_balance at line 708 indicates non-sponsored EvNode transactions don't get proper balance validation.

Recommendation: Move the balance validation logic after the pattern match to ensure all transaction types are properly validated.

2. Error Message Fragility (crates/node/src/validator.rs:248-257)

const UNKNOWN_TX_TYPE_ERROR_MSG: &str = "unexpected tx type";

fn is_unknown_tx_type_error(err: &alloy_rpc_types::engine::PayloadError) -> bool {
    matches!(err, alloy_rpc_types::engine::PayloadError::Decode(_))
        && err.to_string().contains(UNKNOWN_TX_TYPE_ERROR_MSG)
}

Issue: String matching for error detection is fragile and could break with upstream changes.

Recommendation: Consider adding more robust error pattern matching or upstream contribution to add proper error variants.

3. Test Organization

The test utilities are well-designed, but consider extracting the SpanCollector to a shared test crate if tracing tests expand across more modules.

📊 Key Metrics Tracked

The implementation captures essential observability metrics:

  • Performance: duration_ms for all critical operations
  • Transaction Processing: tx_count, tx_hash, nonce, gas_limit
  • Block Operations: block_number, block_hash, parent_hash
  • Validation: payload_id, transaction origin tracking

🎯 Overall Assessment

This is a high-quality implementation that:

  • ✅ Adds valuable observability without performance impact
  • ✅ Follows Rust and tracing best practices
  • ✅ Includes comprehensive test coverage
  • ✅ Maintains code clarity and consistency
  • ✅ Properly handles async contexts with instrumentation

The PR successfully addresses issue #137 and significantly improves the observability of the ev-reth execution flow.


@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cian/add-granular-tracing

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.

Apply review feedback: add duration_ms timing to all instrumented spans,
add block_hash to ensure_well_formed_payload (recorded after computation),
and add tx_hash to the execute_tx error warn log.
Apply review feedback: add duration_ms timing to all instrumented spans,
add block_hash to ensure_well_formed_payload (recorded after computation),
and add tx_hash to the execute_tx error warn log.
@chatton chatton marked this pull request as ready for review February 24, 2026 14:33
@chatton chatton requested a review from a team as a code owner February 24, 2026 14:33
@chatton chatton merged commit 01ffe86 into main Feb 24, 2026
18 checks passed
@chatton chatton deleted the cian/add-granular-tracing branch February 24, 2026 15:39
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.

[FEATURE] Add granular tracing instrumentation with #[instrument]

2 participants