Skip to content

fix(sqlite-native): replace stderr sql trace logging#4629

Closed
NathanFlurry wants to merge 1 commit into04-12-fix_pegboard_repair_follow-up_build_errorsfrom
04-12-fix_sqlite-native_replace_stderr_sql_trace_logging
Closed

fix(sqlite-native): replace stderr sql trace logging#4629
NathanFlurry wants to merge 1 commit into04-12-fix_pegboard_repair_follow-up_build_errorsfrom
04-12-fix_sqlite-native_replace_stderr_sql_trace_logging

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

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)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • 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

@claude
Copy link
Copy Markdown

claude bot commented Apr 13, 2026

PR Review: fix(sqlite-native): replace stderr sql trace logging

This is a clean, targeted fix that correctly addresses a CLAUDE.md style violation (eprintln!tracing::trace!). The changes are straightforward and all four call sites are handled consistently.

Positives

  • Correctly replaces eprintln! with tracing::trace! per the CLAUDE.md rule: "Never use eprintln! or println! for logging in Rust code. Always use tracing macros."
  • Good use of structured logging fields (op = %op_name, duration_us) instead of formatting into the message string.
  • Log message follows the lowercase convention from CLAUDE.md.
  • Appropriate log level: trace is correct for high-frequency, verbose diagnostic output.

Observations

Performance: std::env::var on every KV operation

The RIVET_TRACE_SQL guard calls std::env::var() on every single KV operation, which acquires a mutex on the process environment each time. Given that KV operations are on the hot path for SQLite (called for every read/write/delete), this could add non-trivial overhead in workloads with many small SQLite operations. Consider caching it once at startup:

use std::sync::LazyLock;
static TRACE_SQL: LazyLock<bool> = LazyLock::new(|| std::env::var("RIVET_TRACE_SQL").is_ok());

// Then in each method:
if *TRACE_SQL {
    tracing::trace!(...);
}

This is pre-existing behavior that the PR inherited, so it is not a blocker — but worth addressing in a follow-up if not here.

Duplicate log lines when RIVET_TRACE_SQL is set

When the env var is set, each KV op emits two log lines: the new tracing::trace! ("sql trace kv round-trip") and the existing tracing::debug! ("kv round-trip") just below it, with identical fields. This is also pre-existing, but now that the trace log is a proper tracing call, it may be worth consolidating — if debug always fires, does the conditional trace duplicate add enough signal?

Minor: the as u64 cast

elapsed.as_micros() returns u128. The cast to u64 matches what the existing tracing::debug! already does, so this is consistent — just noting it is technically lossy (though only for durations exceeding ~584,000 years).

Summary

The core fix is correct and aligns with CLAUDE.md. The performance concern with repeated std::env::var calls on the hot path is the one thing worth addressing — either here or in a follow-up. Otherwise, looks good.

@NathanFlurry NathanFlurry marked this pull request as ready for review April 13, 2026 05:10
@NathanFlurry NathanFlurry deleted the branch 04-12-fix_pegboard_repair_follow-up_build_errors April 13, 2026 05:10
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.

1 participant