Skip to content

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Oct 9, 2025

The work to derive code mappings for Java fell short of supporting multi module directory structure.

This adds support for multi module directory structure behind a feature flag.

The work to derive code mappings for Java fell short of supporting multi module directory structure.

This adds support for multi module directory structure behind a feature flag.
@armenzg armenzg self-assigned this Oct 9, 2025
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 9, 2025
cursor[bot]

This comment was marked as outdated.

# com.example.multi.foo.bar.Baz$InnerClass, Baz.kt ->
# stack_root: com/example/multi/foo/
# file_path: com/example/multi/foo/bar/Baz.kt
granularity = STACK_ROOT_MAX_LEVEL
Copy link
Member Author

Choose a reason for hiding this comment

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

The default behaviour is STACK_ROOT_MAX_LEVEL - 1

Image

I will need to investigate other projects where code mappings did not fully work and probably make this the new default.

Copy link
Member

Choose a reason for hiding this comment

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

hm, just wondering, if there are second level TLDs would this still work? E.g. au/com/company/app/feature/ ? Found this repo as an exemplar: https://github.com/Automattic/pocket-casts-android/tree/main/modules/features/account/src/main/java/au/com/shiftyjelly/pocketcasts/account

Copy link
Member Author

Choose a reason for hiding this comment

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

I have filed it as a ticket to follow-up on.

source_root=expected_cm["source_root"],
).first()
code_mapping = current_code_mappings.get(
project_id=self.project.id, stack_root=expected_cm["stack_root"]
Copy link
Member Author

Choose a reason for hiding this comment

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

The index together is the project and the stack root.

project_id=self.project.id, stack_root=expected_cm["stack_root"]
)
assert code_mapping is not None
assert code_mapping.source_root == expected_cm["source_root"]
Copy link
Member Author

Choose a reason for hiding this comment

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

When a test fails, this assertion is better than when source_root did not match (the call to first() would give us None).

expected_new_in_app_stack_trace_rules=["stack.module:android.app.** +app"],
)

def test_multi_module_with_old_granularity(self) -> None:
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the current behaviour without the option.
We will delete this test once we're fully rolled out.

# It's missing the extra granularity
# It's going to pick modY since it is the first frame processed, thus,
# the other frame will not have a working code mapping
self.code_mapping("com/example/multi/", "modules/modY/com/example/multi/")
Copy link
Member Author

Choose a reason for hiding this comment

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

This code mapping will not work for com.example.multi.foo.Bar since the file is found under modules/modX/com.example.multi/foo/Bar.kt.

# the other frame will not have a working code mapping
self.code_mapping("com/example/multi/", "modules/modY/com/example/multi/")
],
expected_new_in_app_stack_trace_rules=["stack.module:com.example.** +app"],
Copy link
Member Author

Choose a reason for hiding this comment

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

This has one degree of granularity than with the new feature.

- stack.module:com.example.** +app
+ stack.module:com.example.multi.** +app

platform=self.platform,
expected_new_code_mappings=[
self.code_mapping(f"{module_prefix}foo/", f"modules/modX/{module_prefix}foo/"),
self.code_mapping(f"{module_prefix}bar/", f"modules/modY/{module_prefix}bar/"),
Copy link
Member Author

Choose a reason for hiding this comment

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

A code mapping per module rather than a single code mapping.

self.code_mapping(f"{module_prefix}bar/", f"modules/modY/{module_prefix}bar/"),
],
expected_new_in_app_stack_trace_rules=[
f"stack.module:{java_module_prefix}.** +app"
Copy link
Member Author

Choose a reason for hiding this comment

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

This has one granularity degree greater than the default behaviour. See previous test.

@armenzg armenzg changed the title feat(auto_source): Multi module support for Java projects feat(auto_source): Derive a code mapping per module Oct 9, 2025
@armenzg armenzg marked this pull request as ready for review October 9, 2025 20:18
@armenzg armenzg requested a review from a team as a code owner October 9, 2025 20:18
@armenzg armenzg requested a review from romtsn October 9, 2025 20:28
return stack_root, file_path


def get_granularity(parts: Sequence[str]) -> int:
Copy link
Member

Choose a reason for hiding this comment

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

I believe this logic is correct, but I'm wondering if we can simplify it, e.g.:

num_segments = len(parts)

if num_segments == 1:
    return 1

# com.example.foo.bar.Baz$InnerClass, Baz.kt ->
#    stack_root: com/example/foo/
#    file_path:  com/example/foo/bar/Baz.kt
granularity = STACK_ROOT_MAX_LEVEL - 1

# com.example.foo.bar.Baz$InnerClass, Baz.kt ->
#    stack_root: com/example/foo/
#    file_path:  com/example/foo/bar/Baz.kt
if parts[1] in SECOND_LEVEL_TLDS:
    granularity = STACK_ROOT_MAX_LEVEL

# com.example.multi.foo.bar.Baz$InnerClass, Baz.kt ->
#    stack_root: com/example/multi/foo/
#    file_path:  com/example/multi/foo/bar/Baz.kt
elif options.get("auto_source_code_config.multi_module_projects_allowlist"):
    granularity = STACK_ROOT_MAX_LEVEL

return granularity

Copy link
Member Author

Choose a reason for hiding this comment

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

That probably makes sense. I will handle it on my next PR.

cursor[bot]

This comment was marked as outdated.

@armenzg armenzg force-pushed the 0/feat/auto_source/java/multi_module/armenzg branch from 7194ad3 to 4d7c7c1 Compare October 14, 2025 11:48
@armenzg armenzg requested a review from a team as a code owner October 14, 2025 11:48
@armenzg
Copy link
Member Author

armenzg commented Oct 14, 2025

bugbot run

cursor[bot]

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #101288      +/-   ##
===========================================
+ Coverage   81.04%    81.08%   +0.03%     
===========================================
  Files        8681      8683       +2     
  Lines      385115    385368     +253     
  Branches    24320     24320              
===========================================
+ Hits       312132    312461     +329     
+ Misses      72624     72548      -76     
  Partials      359       359              

@armenzg armenzg enabled auto-merge (squash) October 14, 2025 12:14
@armenzg armenzg merged commit 1246c04 into master Oct 14, 2025
65 checks passed
@armenzg armenzg deleted the 0/feat/auto_source/java/multi_module/armenzg branch October 14, 2025 12:34
armenzg added a commit that referenced this pull request Oct 14, 2025
Remove option and old code path from #101288.
armenzg added a commit that referenced this pull request Oct 15, 2025
This makes the granularity of the stack root consistent rather than
trying to optimize number of created code mappings.

This also removes the option and old code path from #101288.
chromy pushed a commit that referenced this pull request Oct 17, 2025
The work to derive code mappings for Java fell short of supporting multi
module directory structure.

This adds support for multi module directory structure behind a feature
flag.
chromy pushed a commit that referenced this pull request Oct 17, 2025
This makes the granularity of the stack root consistent rather than
trying to optimize number of created code mappings.

This also removes the option and old code path from #101288.
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants