Skip to content

fix(rust): Fix broken module tree for nested proto packages#185

Merged
dashed merged 4 commits intomainfrom
fix/billing-rust-codegen
Mar 16, 2026
Merged

fix(rust): Fix broken module tree for nested proto packages#185
dashed merged 4 commits intomainfrom
fix/billing-rust-codegen

Conversation

@dashed
Copy link
Member

@dashed dashed commented Mar 13, 2026

Summary

The sentry_protos v0.8.3 Rust crate on crates.io is broken — it fails to compile due to invalid super::super::super:: references in billing.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.rs code generator flattened all proto packages into 2-level name::version modules, discarding intermediate path segments. For example, sentry_protos.billing.v1.services.usage.v1 was mapped to a flat usage::v1 module at the crate root instead of being nested under billing::v1::services::usage::v1.

Prost generates super:: paths based on the full proto package hierarchy. From billing.v1.services.usage.v1, referencing a type in billing.v1 produces super::super::super::DataCategory (3 levels up). But the flat usage::v1 module is only 2 levels deep — so the super:: paths escape above the crate root, causing E0433 compilation errors.

Changes

  • build_rust/src/main.rs: Replaced 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.
  • rust/src/_include.rs: New prost-generated file with correctly nested pub mod declarations.
  • rust/src/lib.rs: Simplified to 2 lines — includes the generated module file and re-exports.
  • .github/workflows/ci.yml: Added cargo check && cargo clippy verification 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 .rs files: unchanged

All sentry_protos.*.rs files are identical between this branch and main. Only the module structure changed.

Public API comparison

Module main This PR Notes
billing::v1 crate::billing::v1 crate::billing::v1 Same (re-exported)
conduit::v1alpha crate::conduit::v1alpha crate::conduit::v1alpha Same
seer::v1 crate::seer::v1 crate::seer::v1 Same
sentry::v1 crate::sentry::v1 crate::sentry::v1 Same
snuba::v1 crate::snuba::v1 crate::snuba::v1 Same
taskbroker::v1 crate::taskbroker::v1 crate::taskbroker::v1 Same
contract::v1 crate::contract::v1 crate::billing::v1::services::contract::v1 Path changed
usage::v1 crate::usage::v1 (broken) crate::billing::v1::services::usage::v1 Fixed

Breaking change

contract::v1 moved from crate::contract::v1 to crate::billing::v1::services::contract::v1. The usage::v1 path change is not a regression since it never compiled.

Test plan

  • cargo check passes
  • cargo clippy passes (no warnings)
  • cargo test passes — 5 integration tests covering cross-package roundtrips, contract types, and default messages
  • All generated .rs proto files are unchanged vs main
  • Verify sentry-kafka-schemas CI passes with this fix released

@github-actions
Copy link

github-actions bot commented Mar 13, 2026

The latest Buf updates on your PR. Results from workflow ci / buf-checks (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed✅ passedMar 13, 2026, 9:21 PM

dashed added 2 commits March 13, 2026 16:57
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.
@dashed dashed force-pushed the fix/billing-rust-codegen branch from aabd91b to 8cdcdcb Compare March 13, 2026 20:57
@dashed dashed self-assigned this Mar 13, 2026
@dashed dashed requested a review from a team March 13, 2026 21:02
@dashed dashed marked this pull request as ready for review March 13, 2026 21:02
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
@dashed dashed force-pushed the fix/billing-rust-codegen branch from 9d2089a to c97327c Compare March 13, 2026 21:12
Copy link
Member

@krithikravi krithikravi left a comment

Choose a reason for hiding this comment

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

lgtm, i was also running into this issue. i'd wait for someone else to chime in on this too though

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Unused regex dependency left in Cargo.toml
    • Removed the unused regex dependency from build_rust/Cargo.toml after confirming no code references it.

Create PR

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().
Copy link
Member

@evanh evanh left a comment

Choose a reason for hiding this comment

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

Thanks for adding all this!

@dashed dashed merged commit ae20bf5 into main Mar 16, 2026
12 checks passed
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.

3 participants