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(inbound-filters): Add inbound filter for ChunkLoadError #57277

Merged
merged 7 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/sentry/api/endpoints/project_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,11 @@ def put(self, request: Request, project) -> Response:
"filters:react-hydration-errors",
bool(options["filters:react-hydration-errors"]),
)
if "filters:chunk-load-error" in options:
project.update_option(
"filters:chunk-load-error",
bool(options["filters:chunk-load-error"]),
)
if "filters:blacklisted_ips" in options:
project.update_option(
"sentry:blacklisted_ips",
Expand Down
1 change: 1 addition & 0 deletions src/sentry/api/serializers/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def format_options(attrs: dict[str, Any]) -> dict[str, Any]:
"sentry:reprocessing_active": bool(options.get("sentry:reprocessing_active", False)),
"filters:blacklisted_ips": "\n".join(options.get("sentry:blacklisted_ips", [])),
"filters:react-hydration-errors": bool(options.get("filters:react-hydration-errors", True)),
"filters:chunk-load-error": bool(options.get("filters:chunk-load-error", True)),
f"filters:{FilterTypes.RELEASES}": "\n".join(
options.get(f"sentry:{FilterTypes.RELEASES}", [])
),
Expand Down
1 change: 1 addition & 0 deletions src/sentry/apidocs/examples/project_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"sentry:reprocessing_active": False,
"filters:blacklisted_ips": "",
"filters:react-hydration-errors": True,
"filters:chunk-load-error": True,
"filters:releases": "",
"filters:error_messages": "",
"feedback:branding": True,
Expand Down
1 change: 1 addition & 0 deletions src/sentry/models/options/project_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"mail:subject_prefix",
"mail:subject_template",
"filters:react-hydration-errors",
"filters:chunk-load-error",
]
)

Expand Down
3 changes: 3 additions & 0 deletions src/sentry/projectoptions/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
# Default react hydration errors filter
register(key="filters:react-hydration-errors", epoch_defaults={1: "1"})

# Default NextJS chunk load error filter
register(key="filters:chunk-load-error", epoch_defaults={1: "1"})

# Default breakdowns config
register(
key="sentry:breakdowns",
Expand Down
5 changes: 5 additions & 0 deletions src/sentry/relay/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def get_filter_settings(project: Project) -> Mapping[str, Any]:
"*https://reactjs.org/docs/error-decoder.html?invariant={418,419,422,423,425}*"
]

enable_chunk_upload_error_filter = project.get_option("filters:chunk-load-error")
if enable_chunk_upload_error_filter:
# ChunkLoadError: Loading chunk 3662 failed.\n(error: https://xxx.com/_next/static/chunks/29107295-0151559bd23117ba.js)
error_messages += ["ChunkLoadError: Loading chunk * failed.\n(error: *)"]
Copy link
Member

Choose a reason for hiding this comment

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

You may want to check in a unit test in relay to make sure this pattern works. See for example getsentry/relay#1903.

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 did write a unit test for it, just wasn't sure if I should make a PR with it. wydt?


if error_messages:
filter_settings["errorMessages"] = {"patterns": error_messages}

Expand Down
14 changes: 14 additions & 0 deletions tests/sentry/api/endpoints/test_project_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ def test_options(self):
"sentry:verify_ssl": False,
"feedback:branding": False,
"filters:react-hydration-errors": True,
"filters:chunk-load-error": True,
}
with self.feature("projects:custom-inbound-filters"), outbox_runner():
self.get_success_response(self.org_slug, self.proj_slug, options=options)
Expand Down Expand Up @@ -716,6 +717,12 @@ def test_options(self):
event=audit_log.get_event_id("PROJECT_EDIT"),
).exists()
assert project.get_option("filters:react-hydration-errors", "1")
with assume_test_silo_mode(SiloMode.CONTROL):
assert AuditLogEntry.objects.filter(
organization_id=project.organization_id,
event=audit_log.get_event_id("PROJECT_EDIT"),
).exists()
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: what does this piece do? It seems duplicated for each option.

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 admit that I have replicated the test without thinking much about it but I have now removed it since semantically it does not make sense, since no mutation of the project options is happening between the checks.

assert project.get_option("filters:chunk-load-error", "1")

def test_bookmarks(self):
self.get_success_response(self.org_slug, self.proj_slug, isBookmarked="false")
Expand Down Expand Up @@ -855,6 +862,13 @@ def test_react_hydration_errors(self):
assert self.project.get_option("filters:react-hydration-errors") == value
assert resp.data["options"]["filters:react-hydration-errors"] == value

def test_chunk_load_error(self):
value = False
options = {"filters:chunk-load-error": value}
resp = self.get_success_response(self.org_slug, self.proj_slug, options=options)
assert self.project.get_option("filters:chunk-load-error") == value
assert resp.data["options"]["filters:chunk-load-error"] == value

def test_relay_pii_config(self):
value = '{"applications": {"freeform": []}}'
resp = self.get_success_response(self.org_slug, self.proj_slug, relayPiiConfig=value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
created: '2023-09-15T07:41:54.167449Z'
created: '2023-10-02T11:41:08.185986Z'
creator: sentry
source: tests/sentry/relay/test_config.py
---
Expand Down Expand Up @@ -83,6 +83,9 @@ config:
errorMessages:
patterns:
- '*https://reactjs.org/docs/error-decoder.html?invariant={418,419,422,423,425}*'
- 'ChunkLoadError: Loading chunk * failed.

(error: *)'
ignoreTransactions:
isEnabled: true
patterns:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
created: '2023-09-15T07:41:54.637425Z'
created: '2023-10-02T11:41:08.393725Z'
creator: sentry
source: tests/sentry/relay/test_config.py
---
Expand Down Expand Up @@ -83,6 +83,9 @@ config:
errorMessages:
patterns:
- '*https://reactjs.org/docs/error-decoder.html?invariant={418,419,422,423,425}*'
- 'ChunkLoadError: Loading chunk * failed.

(error: *)'
ignoreTransactions:
isEnabled: true
patterns:
Expand Down
1 change: 1 addition & 0 deletions tests/sentry/relay/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def test_project_config_uses_filter_features(
default_project.update_option("sentry:error_messages", error_messages)
default_project.update_option("sentry:releases", releases)
default_project.update_option("filters:react-hydration-errors", False)
default_project.update_option("filters:chunk-load-error", False)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have a test to ensure this value produces a valid project config. If the feature is disabled, it won't be validated with the project config. If the config is invalid we will only see it in production when Relay is unable to parse the project config.

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 was going to add it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the test in a follow up commit.


if has_blacklisted_ips:
default_project.update_option("sentry:blacklisted_ips", blacklisted_ips)
Expand Down
Loading