feat(protos): Add proto override system for in-repo proto definitions#115251
Draft
dashed wants to merge 18 commits into
Draft
feat(protos): Add proto override system for in-repo proto definitions#115251dashed wants to merge 18 commits into
dashed wants to merge 18 commits into
Conversation
noahsmartin
reviewed
May 11, 2026
|
|
||
| - `billing/` — billing service protos (data categories, usage, contracts, etc.) | ||
|
|
||
| Other domains (snuba, seer, taskbroker, etc.) remain in the `sentry-protos` pip package until migrated. |
Contributor
There was a problem hiding this comment.
Assuming this was AI generated, we should probably take out the notion of "migrating" and "other domains" since the plan is this is just a temporary version of protos until we decide to switch back to sentry-protos
noahsmartin
reviewed
May 11, 2026
|
|
||
| ## Why This Exists | ||
|
|
||
| Proto definitions used to live exclusively in the `sentry-protos` repo, with a separate pip release cycle. Iterating on protos required publishing a new `sentry-protos` version before sentry could use the changes. This system moves proto source files into the sentry repo itself (`proto/`), compiling them at import time during development and pre-compiling them during CI/deploy for production. |
Contributor
There was a problem hiding this comment.
Where is the pre-compiling during CI? I only see the compiling in initializer.py in this PR. That is at runtime not CI time right?
86d01dd to
14c7de1
Compare
Install a custom import hook that compiles .proto files to _pb2.py modules at import time, bypassing the installed sentry-protos pip package. This eliminates the release cycle friction when iterating on proto definitions during local development. Set SENTRY_PROTO_DEV_DIR to a sentry-protos checkout or place .proto files in {repo_root}/proto/ to activate. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Split the combined proto_dev_loader module into two focused modules: - proto_compiler: build-time tool that compiles .proto files into _pb2.py modules. Supports CLI usage for CI/deploy pre-compilation. - proto_loader: lightweight runtime import hook that serves pre-compiled pb2 overrides with transparent pip fallback. Works in both development (on-demand compilation) and production (pre-compiled only). Fix namespace shadowing bug: the original finder claimed intermediate packages (sentry_protos.billing, etc.) with search paths pointing only to the cache directory, making pip-installed pb2 modules invisible. The new loader only intercepts _pb2 leaf imports and delegates intermediate packages to pip's finder unless they represent new domains not in pip. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add PROTO_OVERRIDE.md with comprehensive guide covering architecture, quick start for dev and prod, import hook internals, the namespace shadowing bug and its fix, directory structure, CLI reference, API reference, supported import patterns, and troubleshooting. Enhance inline comments in proto_compiler.py and proto_loader.py explaining design decisions: why grpcio-tools is lazily imported, why RLock over Lock, why intermediate packages are delegated to pip, and how _pip_package_has avoids recursion in the MetaPathFinder. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add proto/ directory for committing .proto source files directly to the sentry repo. Files here are auto-detected by proto_loader with highest priority, enabling both local dev (auto-compile on import) and prod (pre-compile during build) without a sentry-protos release. Add bin/sync-protos helper script for syncing proto domains from a sentry-protos checkout into proto/. Supports selective domain sync, batch compilation, and status reporting. Defaults to the billing domain and ../sentry-protos. Update PROTO_OVERRIDE.md with in-repo workflow, priority order docs, switching guide, and getsentry integration instructions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Proto sources live in this repo and are edited here directly. The sync script is a one-time migration tool, not an ongoing workflow. Update README and PROTO_OVERRIDE.md to reflect that proto/ is the source of truth, with pip as fallback for non-migrated domains only. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove the "Namespace Shadowing Bug" section and other internal implementation narratives from PROTO_OVERRIDE.md. Simplify code comments to explain what matters, not how we got here. Trim verbose docstrings throughout both modules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Call install() in two places so proto overrides are active before any sentry_protos imports: - runner/initializer.py: before django.setup(), which triggers model imports that reference sentry_protos at module level. - testutils/pytest/sentry.py: in pytest_configure, before initialize_app() and test collection. Both calls are no-ops when no proto/ directory or cache exists. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Both repos share one venv with sentry editable-installed, so proto overrides work automatically in getsentry with no changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The override is transparent — same import paths work regardless of whether the module comes from proto/ or pip. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Required for proto compilation during development (auto-compile on import) and CI build steps. Not needed in production where protos are pre-compiled. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
grpcio-tools is not available on pypi.devinfra.sentry.io yet. Need to add it to getsentry/pypi first before it can be declared as a dependency. For now, it's installed manually or via the existing venv (already present from prior installs). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Now available on pypi.devinfra.sentry.io (getsentry/pypi#2138). Required for proto compilation during development (auto-compile on import) and CI build steps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The production pre-compile step is in getsentry's Dockerfile (js-builder stage), not in this repo. The initializer.py call is runtime only — it serves pre-compiled files, not compiles them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a proto compilation step to the setup-sentry CI action, after fast_editable and before devservices. This pre-compiles protos from proto/ into .proto_cache/ so xdist workers don't race to compile the same files at import time. Conditional on proto/sentry_protos/ existing — no-op until billing protos are migrated. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add grpc_tools and mypy_protobuf to the missing stubs list in pyproject.toml (the sanctioned way to handle untyped third-party modules). Add -> None return annotations to all test methods. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix generator fixture return type (Generator, not None) and add missing -> None to test methods that were missed by the regex. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This is a temporary mechanism for faster iteration on proto definitions, not a permanent migration of ownership away from sentry-protos. Changes should eventually be published back to sentry-protos. Remove "migration" language throughout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b9cc2bd to
346c6a2
Compare
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
sentry-protosmodules with local.protodefinitions for faster iteration, without waiting for asentry-protosreleaseproto/sentry_protos/override the pip package transparently. Changes should eventually be published back tosentry-protosfrom sentry_protos.billing.v1.data_category_pb2 import DataCategoryworks the same whether the module comes fromproto/or pip. No code changes neededArchitecture
Two modules with distinct responsibilities:
proto_compiler.py— build-time tool that compiles.proto→_pb2.py. Has a CLI:python -m sentry.utils.proto_compiler compile --source proto --output .proto_cacheproto_loader.py— lightweight runtime import hook. Interceptssentry_protos.*_pb2imports, serves compiled overrides from.proto_cache/, falls back to pip. In dev mode, triggers compilation on demand when sources change. Only intercepts leaf_pb2imports — intermediate packages are left to pip so non-overridden siblings remain importableAll four paths
install()detectsproto/dir, auto-compiles on import viagrpcio-toolsrunner/initializer.pybeforedjango.setup()pytest_configureintestutils/pytest/sentry.pysetup-sentry/action.ymlafterfast_editablejs-builderstage) —grpcio-toolsin builder only, not in final imageAll steps are no-ops when
proto/has no.protofiles — zero impact until protos are added.Related PRs
grpcio-toolsto private PyPI (MERGED)Included
src/sentry/utils/proto_compiler.py.proto→_pb2.pycompiler with CLIsrc/sentry/utils/proto_loader.pysrc/sentry/utils/PROTO_OVERRIDE.mdproto/README.mdbin/sync-protossrc/sentry/runner/initializer.pyinstall()call beforedjango.setup()src/sentry/testutils/pytest/sentry.pyinstall()call inpytest_configure.github/actions/setup-sentry/action.ymlpyproject.toml+uv.lockgrpcio-toolsadded as dev dependencytests/sentry/utils/test_proto_compiler.pytests/sentry/utils/test_proto_loader.pyTest plan
bin/sync-protoscopies billing protos correctly from sentry-protosfrom sentry_protos.billing.v1.data_category_pb2 import DataCategoryworks with overrides