fix(rust): Fix broken module tree for nested proto packages#185
Merged
Conversation
|
The latest Buf updates on your PR. Results from workflow ci / buf-checks (pull_request).
|
The lib.rs code generator flattened all proto packages into 2-level name::version modules, discarding intermediate path segments. This caused prost's super:: references to resolve incorrectly when a deeply nested package (e.g., billing.v1.services.usage.v1) referenced types from a parent package (billing.v1). Replace the custom ModuleTree code generation with prost-build's built-in include_file() which generates properly nested module declarations matching the proto package hierarchy. A thin lib.rs re-exports the inner sentry_protos module to maintain the existing public API.
The codegen-rust CI job generated Rust bindings and auto-committed them without ever checking if the output compiles. This allowed v0.8.3 to ship with broken generated code (invalid super:: paths in billing.v1.services.usage.v1). Add cargo check + cargo clippy after generation and before the auto-commit step, so broken codegen is caught on the PR.
aabd91b to
8cdcdcb
Compare
Add integration tests that verify: - All expected modules are importable at correct paths - Cross-package type references resolve correctly (the exact bug that broke v0.8.3) - Proto messages roundtrip through prost encode/decode
9d2089a to
c97327c
Compare
krithikravi
approved these changes
Mar 13, 2026
Member
krithikravi
left a comment
There was a problem hiding this comment.
lgtm, i was also running into this issue. i'd wait for someone else to chime in on this too though
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Unused
regexdependency left inCargo.toml- Removed the unused regex dependency from build_rust/Cargo.toml after confirming no code references it.
Or push these changes by commenting:
@cursor push 3af2bb227c
Preview (3af2bb227c)
diff --git a/build_rust/Cargo.toml b/build_rust/Cargo.toml
--- a/build_rust/Cargo.toml
+++ b/build_rust/Cargo.toml
@@ -13,7 +13,6 @@
glob = "0.3.1"
prost = "0.14"
prost-types = "0.14"
-regex = "1.10.5"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
tonic = "0.14"
tonic-prost-build = "0.14"This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Remove regex, prost, prost-types, tokio, and tonic from build_rust/Cargo.toml — all unused after switching to prost-build's include_file().
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
The
sentry_protosv0.8.3 Rust crate on crates.io is broken — it fails to compile due to invalidsuper::super::super::references inbilling.v1.services.usage.v1.rs. This breaks Rust CI in all downstream consumers (e.g., sentry-kafka-schemas PR #476).Root cause
The
build_rust/src/main.rscode generator flattened all proto packages into 2-levelname::versionmodules, discarding intermediate path segments. For example,sentry_protos.billing.v1.services.usage.v1was mapped to a flatusage::v1module at the crate root instead of being nested underbilling::v1::services::usage::v1.Prost generates
super::paths based on the full proto package hierarchy. Frombilling.v1.services.usage.v1, referencing a type inbilling.v1producessuper::super::super::DataCategory(3 levels up). But the flatusage::v1module is only 2 levels deep — so thesuper::paths escape above the crate root, causingE0433compilation errors.Changes
build_rust/src/main.rs: Replaced the customModuleTreecode generation with prost-build's built-ininclude_file(), which generates properly nested module declarations matching the proto package hierarchy. A thinlib.rsre-exports the innersentry_protosmodule to maintain the existing public API.rust/src/_include.rs: New prost-generated file with correctly nestedpub moddeclarations.rust/src/lib.rs: Simplified to 2 lines — includes the generated module file and re-exports..github/workflows/ci.yml: Addedcargo check && cargo clippyverification step after code generation and before auto-commit, so broken codegen is caught on the PR (this was the gap that allowed v0.8.3 to ship broken).rust/tests/codegen_test.rs: New integration tests — compile-time module importability checks, cross-package type reference roundtrips (the exact v0.8.3 bug scenario), and protobuf encode/decode verification.Generated proto
.rsfiles: unchangedAll
sentry_protos.*.rsfiles are identical between this branch and main. Only the module structure changed.Public API comparison
billing::v1crate::billing::v1crate::billing::v1conduit::v1alphacrate::conduit::v1alphacrate::conduit::v1alphaseer::v1crate::seer::v1crate::seer::v1sentry::v1crate::sentry::v1crate::sentry::v1snuba::v1crate::snuba::v1crate::snuba::v1taskbroker::v1crate::taskbroker::v1crate::taskbroker::v1crate::contract::v1crate::billing::v1::services::contract::v1crate::usage::v1(broken)crate::billing::v1::services::usage::v1Breaking change
contract::v1moved fromcrate::contract::v1tocrate::billing::v1::services::contract::v1. Theusage::v1path change is not a regression since it never compiled.Test plan
cargo checkpassescargo clippypasses (no warnings)cargo testpasses — 5 integration tests covering cross-package roundtrips, contract types, and default messages.rsproto files are unchanged vs main