Skip to content

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Mar 7, 2025

This also prepares the code for further changes.

This also prepares the code for further changes.
@armenzg armenzg self-assigned this Mar 7, 2025
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 7, 2025
@armenzg armenzg requested a review from MichaelSun48 March 7, 2025 14:22
trees = get_trees_for_org(installation, org, extra)
trees_helper = CodeMappingTreesHelper(trees)
code_mappings = trees_helper.generate_code_mappings(frames_to_process, platform)
create_repos_and_code_mappings(code_mappings, installation, project, platform)
Copy link
Member Author

Choose a reason for hiding this comment

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

We're also going to be creating in_app stack trace rules, thus, renaming in advance.


organization_id = organization_integration.organization_id
for code_mapping in code_mappings:
repository = (
Copy link
Member Author

Choose a reason for hiding this comment

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

Moving all of the logic from this loop to process_code_mapping. It will make create_configurations shorter and easier to read.


if not repository:
if not dry_run:
if repository is None: # This is mostly to appease the type checker
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 changed the code in such a way that we don't need to make this specific check:
image

@armenzg armenzg marked this pull request as ready for review March 7, 2025 14:30
@armenzg armenzg requested a review from a team as a code owner March 7, 2025 14:30
.first()
)

if not repository:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add some negative metrics here if, say, the code mapping creation fails or one already exists? It might be helpful to understand how often each failure mode is occurring.

Some of those metrics might also belong inside the tree_helpers.generate_code_mappings function

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @MichaelSun48, good point.
I have reworked the code to handle this correctly. There's no need for a metric.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I'm misunderstanding or missing something, but why do we not need a metric? There are definitely cases where we do not create a code mapping because one already exists, right?

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 only time we get to not repository is when we use dry_run=True. It's not possible otherwise.

def create_code_mapping(
code_mapping: CodeMapping,
project: Project,
repository: Repository | 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.

@MichaelSun48 I'm changing this is to Repository | None.

organization_integration: RpcOrganizationIntegration,
dry_run: bool,
) -> None:
if not dry_run and repository:
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 also changed this.

@codecov
Copy link

codecov bot commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #86597   +/-   ##
=========================================
  Coverage          ?   87.79%           
=========================================
  Files             ?     9772           
  Lines             ?   553439           
  Branches          ?    21639           
=========================================
  Hits              ?   485877           
  Misses            ?    67191           
  Partials          ?      371           

@armenzg armenzg merged commit cc85c73 into master Mar 10, 2025
49 checks passed
@armenzg armenzg deleted the ref-1/auto_source/armenzg branch March 10, 2025 12:02
@sentry
Copy link

sentry bot commented Mar 10, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ IntegrityError: UniqueViolation('duplicate key value violates unique constraint "sentry_repositoryproject_project_id_stack_root_e376b891_uniq"\nDETAIL: Key (project_id, stack_root)=(4507972001136720, contexts/) already exists.\n') sentry.tasks.auto_source_code_config View Issue
  • ‼️ IntegrityError: UniqueViolation('duplicate key value violates unique constraint "sentry_repositoryproject_project_id_stack_root_e376b891_uniq"\nDETAIL: Key (project_id, stack_root)=(4508094181343312, /Users/romain.louvet/Documents/workspace/travelplanner-airbnb/) alre... sentry.tasks.auto_source_code_config View Issue

Did you find this useful? React with a 👍 or 👎

@armenzg armenzg added the Trigger: Revert Add to a merged PR to revert it (skips CI) label Mar 10, 2025
@getsentry-bot
Copy link
Contributor

PR reverted: f2d672c

getsentry-bot added a commit that referenced this pull request Mar 10, 2025
armenzg added a commit that referenced this pull request Mar 20, 2025
…ories

In #86597 I introduced a bug causing many [IntegrityErrors](https://sentry.sentry.io/issues/?environment=prod&groupStatsPeriod=auto&page=0&project=1&query=error.type%3AIntegrityError%20transaction%3Asentry.tasks.auto_source_code_config&referrer=issue-list&statsPeriod=90d) because we called `create` when the code mapping already existed.

This change is to have a test to prevent trying to create the repository or code mappings more than once.
armenzg added a commit that referenced this pull request Mar 20, 2025
In #86597 I introduced a bug causing many [IntegrityErrors](https://sentry.sentry.io/issues/?environment=prod&groupStatsPeriod=auto&page=0&project=1&query=error.type%3AIntegrityError%20transaction%3Asentry.tasks.auto_source_code_config&referrer=issue-list&statsPeriod=90d) because we called `create` when the code mapping already existed.

This change is to have a test to prevent trying to create the repository or code mappings more than once.
armenzg added a commit that referenced this pull request Mar 21, 2025
… repositories (#87498)

This change adds testing the creation of code mappings based on data
from different repositories to prevent future regressions (In #86597 I
refactored the code and introduced a regression).

This change will not prevent the regression but it will make the
follow-up PR to fix it.
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 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 Trigger: Revert Add to a merged PR to revert it (skips CI)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants