Skip to content

refactor(rust_bridge): give the logger module one role and split it by concern - #53690

Merged
yujonglee-berri merged 1 commit into
mainfrom
litellm_python_bridge_logger_module_split
Nov 23, 2026
Merged

yujonglee-berri merged 1 commit into
mainfrom
litellm_python_bridge_logger_module_split

Conversation

@yujonglee-berri

@yujonglee-berri yujonglee-berri commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

[insert handwritten description here]

Details

TLDR

Problem this solves:

  • python-bridge/src/logger did not say what it is for
  • It mixed Rust-to-Python log delivery with redaction classes Python calls
  • Its calls into Python were spread over three unrelated functions
  • Its tests sat in a sibling tests.rs, which the Rust rules forbid

How it solves it:

  • logger only delivers Rust tracing events to Python logging
  • The redaction classes move to python-bridge/src/redaction.rs
  • logger/host.rs holds every call into litellm.rust_bridge.host.logger
  • The sink and the level cache each get a file, tests inline
  • Each file opens with one line saying what it is for

Relevant issues

Base of the stack for #53539

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

E2E exception at 98e7efd.

Scope. The diff reorganizes litellm/rust/crates/python-bridge/src/logger/ and changes nothing a caller or an operator can observe. No test was added, removed or rewritten.

Rationale. Almost all of the diff is code moving between files. processing.rs becomes redaction.rs unchanged, and its three importers (lib.rs, spend_log.rs, spend_log_rows.rs) switch to the new path. The Python classes keep their names, so nothing on the Python side changes. tests.rs is split between sink.rs and levels.rs, and the only edits inside it are super:: paths and two strings in the delivery test that name the file and module the test itself lives in.

One part is a small rewrite and not a move. The three calls into litellm.rust_bridge.host.logger (context, enabled, emit) used to sit inside three unrelated functions and now are three functions in host.rs with the same bodies. Reading the request correlation returns an Option there, and a call falls back to the default no-op logger when Python cannot provide one, exactly as before. The items the rest of the crate uses (capture, capture_call, LoggedMachine) keep their paths.

Commands and results, from litellm/rust.

cargo fmt -p litellm-python-bridge -p litellm-tracing -p litellm-redis-store -- --check
cargo clippy -q -p litellm-python-bridge -p litellm-tracing -p litellm-redis-store --all-targets -- -D warnings
PYTHONPATH=<site-packages of a Python 3.14 env with the project's dependencies> LITELLM_MODE=PRODUCTION \
  cargo test -q -p litellm-python-bridge --lib -- logger --nocapture
(fmt and clippy print nothing and exit 0)

running 10 tests
..........
test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 494 filtered out; finished in 3.40s

native_events_reach_python_with_levels_context_reentry_and_http_deduplication prints SKIP and passes when the embedded interpreter cannot import the project's packages, so the run above puts them on PYTHONPATH and the test ran for real. It drives all three Python calls through a route machine, a sync call and an async call, and checks levels and request correlation on the Python side, so it covers the rewritten part.

Type

🧹 Refactoring

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Devin Review

…y concern

logger/mod.rs held the bridge from Rust tracing to Python logging together
with two redaction classes that Python calls the other way, and its tests
sat in a sibling tests.rs that the Rust workspace rules no longer allow.

The module now only delivers Rust tracing events to Python logging. The
redaction classes move to redaction.rs. Every call into
litellm.rust_bridge.host.logger sits in logger/host.rs, one function per
Python function. The sink and the per-call level cache each get a file
with their tests inline, and each file says what it is for. No behavior
changes.
@veria-ai

veria-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 2 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yujonglee-berri

Copy link
Copy Markdown
Contributor Author

@greptileai please review this PR. It is the bottom of a stack, so its diff against main is the whole change.

@yujonglee-berri yujonglee-berri added the autoapprove This PR may be autoapproved by greptile. The author thinks that it does not need human review. label Nov 23, 2026
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with no new actionable issues found.

Summary

Splits Rust-to-Python logging into host.rs, sink.rs, and levels.rs. Moves the Python redaction classes into redaction.rs and places the existing tests inline.

No new actionable issues found. Python calls, error fallback, level checks, and class exports keep their existing behavior.

yujonglee-berri dismissed the earlier doc-comment finding because litellm/rust/AGENTS.md asks for documentation in the Rust workspace. The comments remain, as requested.

  • Rust log events still reach Python through a dedicated logger path.
  • Python's native redactors now live apart from Rust log delivery.

Reviews (2) · Last reviewed commit: "refactor(rust_bridge): give the logger m..." · Reviewed by Greptile

@yujonglee-berri

Copy link
Copy Markdown
Contributor Author

@greptileai the doc comments stay, per litellm/rust/AGENTS.md, which asks for them in the Rust workspace. Please review again with that rule in mind.

@yujonglee-berri
yujonglee-berri merged commit 9800ff7 into main Nov 23, 2026
70 of 71 checks passed
@yujonglee-berri
yujonglee-berri deleted the litellm_python_bridge_logger_module_split branch November 23, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autoapprove This PR may be autoapproved by greptile. The author thinks that it does not need human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant