Skip to content

Commit

Permalink
fix: Do not require fully qualified url for node events (#54362)
Browse files Browse the repository at this point in the history
This is something that was never ported, yet existed since forever in
the processing pipeline -
https://github.com/getsentry/sentry/blob/cac31d65fda2cda9b88cd14c54a05039aa76b92b/src/sentry/lang/javascript/processor.py#L1503-L1509
  • Loading branch information
kamilogorek authored Aug 8, 2023
1 parent 55d0356 commit b8f6380
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sentry/api/helpers/source_map_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def source_map_debug(project, event_id, exception_idx, frame_idx):
# already mapped
return SourceMapDebug()

# We can't demangle node's internal modules therefore we only process
# user-land frames (starting with /) or those created by bundle/webpack internals.
if event.platform == "node" and not abs_path.startswith(("/", "app:", "webpack:")):
return SourceMapDebug()

sdk_info = event.data.get("sdk")
can_use_debug_id = (
sdk_info
Expand All @@ -59,7 +64,9 @@ def source_map_debug(project, event_id, exception_idx, frame_idx):

urlparts = urlparse(abs_path)

if not (urlparts.scheme and urlparts.path):
# Node will produce file paths and not a fully-qualified URLs, so we don't need to check it.
# It's also guaranteed here that we will have a valid path, as we verify it few lines above.
if event.platform != "node" and not (urlparts.scheme and urlparts.path):
return SourceMapDebug(
issue=SourceMapProcessingIssue.URL_NOT_VALID, data={"absPath": abs_path}
)
Expand Down
101 changes: 101 additions & 0 deletions tests/sentry/api/endpoints/test_source_map_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,107 @@ def test_no_valid_url(self):
assert error["message"] == "The absolute path url is not valid"
assert error["data"] == {"absPath": "app.example.com/static/js/main.fa8fe19f.js"}

def test_skips_node_internals(self):
event = self.store_event(
data={
"event_id": "a" * 32,
"platform": "node",
"exception": {
"values": [
{
"type": "TypeError",
"stacktrace": {
"frames": [
{
"abs_path": "node:vm",
"filename": "/static/js/main.fa8fe19f.js",
"lineno": 5,
"colno": 45,
}
]
},
},
]
},
},
project_id=self.project.id,
)

resp = self.get_success_response(
self.organization.slug,
self.project.slug,
event.event_id,
frame_idx=0,
exception_idx=0,
)
assert len(resp.data["errors"]) == 0

def test_no_valid_url_skips_node(self):
event = self.store_event(
data={
"event_id": "a" * 32,
"release": "my-release",
"platform": "node",
"exception": {
"values": [
{
"type": "TypeError",
"stacktrace": {
"frames": [
{
"abs_path": "/path/to/file/thats/not/url/main.fa8fe19f.js",
"filename": "/static/js/main.fa8fe19f.js",
"lineno": 5,
"colno": 45,
}
]
},
},
]
},
},
project_id=self.project.id,
)
release = Release.objects.get(organization=self.organization, version=event.release)
release.update(user_agent="test_user_agent")

file = File.objects.create(
name="application.js",
type="release.file",
headers={"Sourcemap": "/path/to/file/thats/not/url/main.fa8fe19f.js.map"},
)
fileobj = ContentFile(b"wat")
file.putfile(fileobj)

ReleaseFile.objects.create(
organization_id=self.project.organization_id,
release_id=release.id,
file=file,
name="/path/to/file/thats/not/url/main.fa8fe19f.js",
)

sourcemapfile = File.objects.create(
name="/path/to/file/thats/not/url/main.fa8fe19f.js.map", type="release.file"
)
sourcemapfileobj = ContentFile(b"wat")
sourcemapfile.putfile(sourcemapfileobj)

ReleaseFile.objects.create(
organization_id=self.project.organization_id,
release_id=release.id,
file=sourcemapfile,
name="/path/to/file/thats/not/url/main.fa8fe19f.js.map",
)

resp = self.get_success_response(
self.organization.slug,
self.project.slug,
event.event_id,
frame_idx=0,
exception_idx=0,
)
assert len(resp.data["errors"]) == 0

def test_partial_url_match(self):
event = self.store_event(
data={
Expand Down

0 comments on commit b8f6380

Please sign in to comment.