Skip to content

Commit 934c32c

Browse files
chore(sentry apps): Ignore RestircedIPAddress error (#95680)
1 parent bbf7629 commit 934c32c

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/sentry/sentry_apps/metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SentryAppWebhookHaltReason(StrEnum):
6868
GOT_CLIENT_ERROR = "got_client_error"
6969
INTEGRATOR_ERROR = "integrator_error"
7070
MISSING_INSTALLATION = "missing_installation"
71+
RESTRICTED_IP = "restricted_ip"
7172

7273

7374
class SentryAppExternalRequestFailureReason(StrEnum):

src/sentry/sentry_apps/tasks/sentry_apps.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from sentry.constants import SentryAppInstallationStatus
1616
from sentry.db.models.base import Model
1717
from sentry.eventstore.models import BaseEvent, Event, GroupEvent
18+
from sentry.exceptions import RestrictedIPAddress
1819
from sentry.hybridcloud.rpc.caching import region_caching_service
1920
from sentry.issues.issue_occurrence import IssueOccurrence
2021
from sentry.models.activity import Activity
@@ -48,7 +49,7 @@
4849
from sentry.taskworker.config import TaskworkerConfig
4950
from sentry.taskworker.constants import CompressionType
5051
from sentry.taskworker.namespaces import sentryapp_control_tasks, sentryapp_tasks
51-
from sentry.taskworker.retry import Retry, retry_task
52+
from sentry.taskworker.retry import NoRetriesRemainingError, Retry, retry_task
5253
from sentry.types.rules import RuleFuture
5354
from sentry.users.services.user.model import RpcUser
5455
from sentry.users.services.user.service import user_service
@@ -78,7 +79,14 @@
7879

7980
retry_decorator = retry(
8081
on=(RequestException, ApiHostError, ApiTimeoutError),
81-
ignore=(ClientError, SentryAppSentryError, AssertionError, ValueError),
82+
ignore=(
83+
ClientError,
84+
SentryAppSentryError,
85+
AssertionError,
86+
ValueError,
87+
RestrictedIPAddress,
88+
NoRetriesRemainingError,
89+
),
8290
ignore_and_capture=(),
8391
)
8492

src/sentry/utils/sentry_apps/webhooks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from rest_framework import status
1010

1111
from sentry import options
12+
from sentry.exceptions import RestrictedIPAddress
1213
from sentry.http import safe_urlopen
1314
from sentry.sentry_apps.metrics import (
1415
SentryAppEventType,
@@ -120,6 +121,11 @@ def send_and_save_webhook_request(
120121
lifecycle.record_halt(e)
121122
# Re-raise the exception because some of these tasks might retry on the exception
122123
raise
124+
except RestrictedIPAddress:
125+
lifecycle.record_halt(
126+
halt_reason=f"send_and_save_webhook_request.{SentryAppWebhookHaltReason.RESTRICTED_IP}"
127+
)
128+
raise
123129

124130
track_response_code(response.status_code, slug, event)
125131
buffer.add_request(

tests/sentry/sentry_apps/tasks/test_sentry_apps.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from sentry.constants import SentryAppStatus
1111
from sentry.eventstore.models import GroupEvent
1212
from sentry.eventstream.types import EventStreamEventType
13+
from sentry.exceptions import RestrictedIPAddress
1314
from sentry.integrations.types import EventLifecycleOutcome
1415
from sentry.issues.ingest import save_issue_occurrence
1516
from sentry.models.activity import Activity
@@ -568,6 +569,30 @@ def test_group_created_sends_webhook(self, mock_record, safe_urlopen):
568569
mock_record=mock_record, outcome=EventLifecycleOutcome.SUCCESS, outcome_count=4
569570
)
570571

572+
@patch("sentry_sdk.capture_exception")
573+
def test_ignores_restricted_ip_error(self, capture_exception, safe_urlopen):
574+
safe_urlopen.side_effect = RestrictedIPAddress("12.8391.231")
575+
576+
event = self.store_event(data={}, project_id=self.project.id)
577+
assert event.group is not None
578+
579+
# The task should complete without retrying when RestrictedIPAddress is raised
580+
# because it's in the ignore list of the retry decorator
581+
with self.tasks():
582+
post_process_group(
583+
is_new=True,
584+
is_regression=False,
585+
is_new_group_environment=False,
586+
cache_key=write_event_to_cache(event),
587+
group_id=event.group_id,
588+
project_id=self.project.id,
589+
eventstream_type=EventStreamEventType.Error.value,
590+
)
591+
592+
# Verify that the exception was not captured by Sentry since it's ignored
593+
assert len(capture_exception.mock_calls) == 0
594+
assert safe_urlopen.called
595+
571596
@patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
572597
def test_does_not_process_no_event(self, mock_record, safe_urlopen):
573598
process_resource_change_bound(

0 commit comments

Comments
 (0)