Skip to content

feat(code-mappings): Handle Java monorepo source roots in auto-derivation task#112655

Merged
romtsn merged 4 commits intomasterfrom
rz/feat/java-monorepo-code-mappings
Apr 13, 2026
Merged

feat(code-mappings): Handle Java monorepo source roots in auto-derivation task#112655
romtsn merged 4 commits intomasterfrom
rz/feat/java-monorepo-code-mappings

Conversation

@romtsn
Copy link
Copy Markdown
Member

@romtsn romtsn commented Apr 10, 2026

Summary

  • derive Java/Kotlin source roots from repo tree structure so monorepo modules map to their package root instead of stopping at src/main/java or src/main/kotlin
  • allow multiple code mappings from the same repo when identical Java package paths exist in multiple subprojects
  • move the Java-specific helper logic into a dedicated utility module and add realistic monorepo coverage for GraphQL and OpenTelemetry layouts from sentry-java

Test Plan

  • .venv/bin/pytest -svv --reuse-db tests/sentry/issues/auto_source_code_config/test_code_mapping.py tests/sentry/api/endpoints/issues/test_organization_derive_code_mappings.py tests/sentry/issues/auto_source_code_config/test_process_event.py
  • .venv/bin/pre-commit run --files src/sentry/issues/auto_source_code_config/code_mapping.py src/sentry/issues/auto_source_code_config/utils/java.py tests/sentry/issues/auto_source_code_config/test_code_mapping.py tests/sentry/api/endpoints/issues/test_organization_derive_code_mappings.py tests/sentry/issues/auto_source_code_config/test_process_event.py

Migration

  • no migration needed; RepositoryProjectPathConfig already uses (project, stack_root, source_root) and this PR only changes derivation logic plus an in-memory dedupe key

@romtsn romtsn requested review from a team as code owners April 10, 2026 09:50
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 10, 2026
@romtsn romtsn changed the title feat(code-mappings): handle Java monorepo source roots feat(code-mappings): Handle Java monorepo source roots in auto-derivation task Apr 10, 2026
@romtsn romtsn requested a review from armenzg April 10, 2026 09:57
Copy link
Copy Markdown
Contributor

@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 is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 619ca2e. Configure here.

Comment thread src/sentry/issues/auto_source_code_config/code_mapping.py Outdated
Copy link
Copy Markdown
Member

@armenzg armenzg left a comment

Choose a reason for hiding this comment

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

Amazing!

from collections.abc import Sequence

SLASH = "/"
JAVA_SOURCE_ROOT_MARKERS = ("src/main/java/", "src/main/kotlin/")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As per convo with @romtsn , these are to cover the majority of cases.

# e.g. com.foo.bar.Baz$handle$1, Baz.kt -> com/foo/bar/Baz.kt
"extract_filename_from_module": True,
"create_in_app_stack_trace_rules": True,
"source_roots_resolver": find_java_source_roots,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm glad seeing this file still being a good source for declaring the configuration of each platform 🦾

platform="java",
)

assert sorted(code_mappings) == sorted(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting! We create multiple code mappings!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, courtesy of #111704 :)

@romtsn romtsn merged commit 7041372 into master Apr 13, 2026
59 checks passed
@romtsn romtsn deleted the rz/feat/java-monorepo-code-mappings branch April 13, 2026 19:27
wedamija pushed a commit that referenced this pull request Apr 13, 2026
…tion task (#112655)

## Summary
- derive Java/Kotlin source roots from repo tree structure so monorepo
modules map to their package root instead of stopping at `src/main/java`
or `src/main/kotlin`
- allow multiple code mappings from the same repo when identical Java
package paths exist in multiple subprojects
- move the Java-specific helper logic into a dedicated utility module
and add realistic monorepo coverage for GraphQL and OpenTelemetry
layouts from [sentry-java](https://github.com/getsentry/sentry-java)

## Test Plan
- `.venv/bin/pytest -svv --reuse-db
tests/sentry/issues/auto_source_code_config/test_code_mapping.py
tests/sentry/api/endpoints/issues/test_organization_derive_code_mappings.py
tests/sentry/issues/auto_source_code_config/test_process_event.py`
- `.venv/bin/pre-commit run --files
src/sentry/issues/auto_source_code_config/code_mapping.py
src/sentry/issues/auto_source_code_config/utils/java.py
tests/sentry/issues/auto_source_code_config/test_code_mapping.py
tests/sentry/api/endpoints/issues/test_organization_derive_code_mappings.py
tests/sentry/issues/auto_source_code_config/test_process_event.py`

## Migration
- no migration needed; `RepositoryProjectPathConfig` already uses
`(project, stack_root, source_root)` and this PR only changes derivation
logic plus an in-memory dedupe key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants