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

chore(sentry apps): Improve Sentry App Errors #81877

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

Christinarlong
Copy link
Contributor

@Christinarlong Christinarlong commented Dec 9, 2024

Introduces two classes to represent Sentry App exceptions:
SentryAppError should be used to represent client side errors like failed validation. For the webhook, these should not be sent to the integrator.
SentryAppIntegratorError is used to represent errors between Sentry & the integrator, i.e connection failed, integrator response is incorrect etc. These should be sent to the integrator for the webhook.

For this PR, we want to start wrapping errors in the SentryApp flows with these distinctions. And then in the endpoints we want to catch these two specific errors and return the error message. More info here in notion

This PR is kinda two PRs in one, because I wanted to refactor the alert rule creation flow for Sentry Apps. Currently creating an alert rule for sentry apps has a really weird flow where we don't raise errors until very late.

Context for Alert Rule Sentry App creation: Notion doc

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 9, 2024
Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 89.62963% with 14 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/sentry_apps/utils/alert_rule_action.py 91.52% 5 Missing ⚠️
...s/external_requests/alert_rule_action_requester.py 72.72% 3 Missing ⚠️
...ps/api/endpoints/installation_external_requests.py 60.00% 2 Missing ⚠️
src/sentry/sentry_apps/services/app/impl.py 75.00% 2 Missing ⚠️
...rc/sentry/sentry_apps/alert_rule_action_creator.py 88.88% 1 Missing ⚠️
...try_apps/external_requests/issue_link_requester.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #81877      +/-   ##
==========================================
+ Coverage   80.33%   80.60%   +0.27%     
==========================================
  Files        7272     7259      -13     
  Lines      321230   324846    +3616     
  Branches    20941    20793     -148     
==========================================
+ Hits       258051   261857    +3806     
+ Misses      62784    62590     -194     
- Partials      395      399       +4     

src/sentry/api/endpoints/project_rules.py Fixed Show fixed Hide fixed
return Response(
{"error": e.message},
{"error": str(e)},

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.
Stack trace information
flows to this location and may be exposed to an external user.
Stack trace information
flows to this location and may be exposed to an external user.
Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix AI 27 days ago

To fix the problem, we should ensure that detailed error information is logged on the server while returning a generic error message to the user. This can be achieved by logging the exception details and returning a user-friendly error message in the response.

  • Modify the code to log the exception details using the logger and return a generic error message to the user.
  • Ensure that the logging captures sufficient information for debugging purposes without exposing sensitive details to the end user.
Suggested changeset 1
src/sentry/sentry_apps/api/endpoints/installation_external_requests.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/sentry/sentry_apps/api/endpoints/installation_external_requests.py b/src/sentry/sentry_apps/api/endpoints/installation_external_requests.py
--- a/src/sentry/sentry_apps/api/endpoints/installation_external_requests.py
+++ b/src/sentry/sentry_apps/api/endpoints/installation_external_requests.py
@@ -45,4 +45,5 @@
         except (SentryAppIntegratorError, SentryAppError) as e:
+            logger.error("Error occurred while getting Select FormField options: %s", str(e))
             return Response(
-                {"error": str(e)},
+                {"error": "An error occurred while processing your request."},
                 status=400,
EOF
@@ -45,4 +45,5 @@
except (SentryAppIntegratorError, SentryAppError) as e:
logger.error("Error occurred while getting Select FormField options: %s", str(e))
return Response(
{"error": str(e)},
{"error": "An error occurred while processing your request."},
status=400,
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
trigger_sentry_app_action_creators_for_incidents(serialized_data)
except (SentryAppError, SentryAppIntegratorError) as e:
return Response(
str(e),

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix AI 26 days ago

To fix the problem, we need to ensure that the exception messages returned to the user do not contain sensitive information. Instead, we should log the detailed error message on the server and return a generic error message to the user. This can be achieved by modifying the exception handling blocks to log the error and return a generic message.

Suggested changeset 1
src/sentry/sentry_apps/utils/alert_rule_action.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/sentry/sentry_apps/utils/alert_rule_action.py b/src/sentry/sentry_apps/utils/alert_rule_action.py
--- a/src/sentry/sentry_apps/utils/alert_rule_action.py
+++ b/src/sentry/sentry_apps/utils/alert_rule_action.py
@@ -41,4 +41,5 @@
     except (SentryAppError, SentryAppIntegratorError) as e:
+        sentry_sdk.capture_exception(e)
         return Response(
-            str(e),
+            "An error occurred while processing your request.",
             status=status.HTTP_400_BAD_REQUEST,
@@ -60,4 +61,5 @@
     except (SentryAppError, SentryAppIntegratorError) as e:
+        sentry_sdk.capture_exception(e)
         return Response(
-            {"actions": [str(e)]},
+            {"actions": ["An error occurred while processing your request."]},
             status=status.HTTP_400_BAD_REQUEST,
EOF
@@ -41,4 +41,5 @@
except (SentryAppError, SentryAppIntegratorError) as e:
sentry_sdk.capture_exception(e)
return Response(
str(e),
"An error occurred while processing your request.",
status=status.HTTP_400_BAD_REQUEST,
@@ -60,4 +61,5 @@
except (SentryAppError, SentryAppIntegratorError) as e:
sentry_sdk.capture_exception(e)
return Response(
{"actions": [str(e)]},
{"actions": ["An error occurred while processing your request."]},
status=status.HTTP_400_BAD_REQUEST,
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

except (SentryAppError, SentryAppIntegratorError) as e:
return Response(
{"actions": [str(e)]},

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix AI 26 days ago

To fix the problem, we need to ensure that the exception messages returned to the user do not contain sensitive information. Instead, we should log the detailed exception information and return a generic error message to the user. This can be achieved by modifying the exception handling blocks to log the exception and return a generic error message.

Suggested changeset 1
src/sentry/sentry_apps/utils/alert_rule_action.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/sentry/sentry_apps/utils/alert_rule_action.py b/src/sentry/sentry_apps/utils/alert_rule_action.py
--- a/src/sentry/sentry_apps/utils/alert_rule_action.py
+++ b/src/sentry/sentry_apps/utils/alert_rule_action.py
@@ -60,4 +60,5 @@
     except (SentryAppError, SentryAppIntegratorError) as e:
+        sentry_sdk.capture_exception(e)
         return Response(
-            {"actions": [str(e)]},
+            {"actions": ["An error occurred while processing the request."]},
             status=status.HTTP_400_BAD_REQUEST,
EOF
@@ -60,4 +60,5 @@
except (SentryAppError, SentryAppIntegratorError) as e:
sentry_sdk.capture_exception(e)
return Response(
{"actions": [str(e)]},
{"actions": ["An error occurred while processing the request."]},
status=status.HTTP_400_BAD_REQUEST,
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@getsantry
Copy link
Contributor

getsantry bot commented Jan 3, 2025

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added Stale and removed Stale labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant