Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sourcemaps): Add logic to insert data into new debug ids table #44885

Merged
merged 48 commits into from
Mar 6, 2023

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented Feb 21, 2023

This PR aims at implementing the logic for extracting debug_ids information from the manifest.json of the uploaded .zip artifact bundle.

The new logic reads the updated manifest.json file and looks for the header.debug-id and project fields.

A sample manifest.json can be seen here:

{
  "org": "123",
  "files": {
    "files/_/_/index.js.map": {
      "url": "~/index.js.map",
      "type": "source_map",
      "headers": {
        "debug-id": "eb6e60f1-65ff-4f6f-adff-f1bbeded627b"
      }
    },
    "files/_/_/index.js": {
      "url": "~/index.js",
      "type": "source",
      "headers": {
        "Sourcemap": "index.js.map",
        "debug-id": "eb6e60f1-65ff-4f6f-adff-f1bbeded627b"
      }
    }
  }
}

@iambriccardo iambriccardo changed the title riccardo/feat/debug ids upload feat(sourcemaps): Add logic to insert data into new debug ids table Feb 21, 2023
@github-actions github-actions bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels Feb 21, 2023
@github-actions
Copy link
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 22, 2023

size-limit report 📦

Path Size
src/sentry/static/sentry/dist/entrypoints/app.js 19.9 KB (-0.11% 🔽)
src/sentry/static/sentry/dist/entrypoints/sentry.css 32.99 KB (-0.02% 🔽)

},
"files/_/_/index.js": {
"url": "~/index.js",
"type": "source",
Copy link
Member

Choose a reason for hiding this comment

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

source cannot have debug ids, this has to be minified_source.


schema = {
"type": "object",
"properties": {
Copy link
Member

Choose a reason for hiding this comment

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

I would put an projects key into the schema and then allow the request to specify one or more projects for association. That would also mean that assemble_artifacts takes a list of project IDs rather than one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I still didn't implement the new schema for the endpoint

file_type = info.get("type", None)

if debug_id is not None and file_type is not None:
debug_ids_with_types.append((SourceFileType.from_lowercase_key(file_type), debug_id))
Copy link
Member

Choose a reason for hiding this comment

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

This could return None, needs to be guarded against.

files = manifest.get("files", {})
for filename, info in files.items():
headers = _normalize_headers(info.get("headers", {}))
debug_id = _normalize_debug_id(headers.get("debug-id", None))
Copy link
Member

Choose a reason for hiding this comment

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

I would explicitly check if the debug-id is not None before calling into normalize_debug_id and swallowing the error there.

assert details is None

for debug_id in debug_ids:
debug_id_artifact_bundles = DebugIdArtifactBundle.objects.filter(debug_id=debug_id)
Copy link
Member

Choose a reason for hiding this comment

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

It would be dangerous to write code like this outside of tests becauase it can leak cross organization data (eg: same debug id existing in more than one org). Before someone copy pastes this elsewhere, please make sure that this has the organization_id as constraint too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah, thanks for the heads-up! I forgot about that

@iambriccardo iambriccardo requested review from Swatinem and removed request for a team February 28, 2023 09:46
debug_ids_with_types = []

files = manifest.get("files", {})
for filename, info in files.items():
Copy link
Member Author

Choose a reason for hiding this comment

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

Rename filename to file_path.

@codecov
Copy link

codecov bot commented Mar 2, 2023

Codecov Report

Merging #44885 (f5e2924) into master (2412237) will decrease coverage by 0.06%.
The diff coverage is 92.62%.

❗ Current head f5e2924 differs from pull request most recent head 5141972. Consider uploading reports for the commit 5141972 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #44885      +/-   ##
==========================================
- Coverage   80.24%   80.19%   -0.06%     
==========================================
  Files        4725     4725              
  Lines      198780   199078     +298     
  Branches    12006    12030      +24     
==========================================
+ Hits       159519   159646     +127     
- Misses      38999    39170     +171     
  Partials      262      262              
Impacted Files Coverage Δ
...try/api/endpoints/organization_release_assemble.py 87.17% <ø> (ø)
src/sentry/conf/server.py 93.80% <ø> (ø)
src/sentry/models/artifactbundle.py 98.50% <87.50%> (-1.50%) ⬇️
src/sentry/tasks/assemble.py 85.33% <91.07%> (+1.63%) ⬆️
.../endpoints/organization_artifactbundle_assemble.py 92.68% <92.68%> (ø)
src/sentry/api/bases/organization.py 97.54% <100.00%> (+0.06%) ⬆️
src/sentry/api/endpoints/chunk.py 88.75% <100.00%> (+0.43%) ⬆️
src/sentry/api/urls.py 100.00% <100.00%> (ø)
src/sentry/features/__init__.py 100.00% <100.00%> (ø)
src/sentry/testutils/factories.py 95.43% <100.00%> (+0.16%) ⬆️
... and 79 more

@mitsuhiko mitsuhiko merged commit 14a6b2c into master Mar 6, 2023
@mitsuhiko mitsuhiko deleted the riccardo/feat/debug-ids-upload branch March 6, 2023 09:09
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2023
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 Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants