Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

sentry: Do not report errors tlaking to Sentry, to Sentry.

Alex Vandiver9519945dc0e1
diff --git a/zerver/views/sentry.py b/zerver/views/sentry.py
index ba7f98f459a..46f76fc95d1 100644
--- a/zerver/views/sentry.py
+++ b/zerver/views/sentry.py
@@ -1,3 +1,4 @@
+import logging
import urllib
from contextlib import suppress
@@ -6,11 +7,18 @@ from django.conf import settings
from django.http import HttpRequest, HttpResponse
from django.utils.translation import gettext as _
from django.views.decorators.csrf import csrf_exempt
+from requests.exceptions import RequestException
+from sentry_sdk.integrations.logging import ignore_logger
from zerver.lib.exceptions import JsonableError
from zerver.lib.outgoing_http import OutgoingSession
from zerver.lib.validator import check_url, to_wild_value
+# In order to not overload Sentry if it's having a bad day, we tell
+# Sentry to ignore exceptions that we have when talking to Sentry.
+logger = logging.getLogger(__name__)
+ignore_logger(logger.name)
+
class SentryTunnelSession(OutgoingSession):
def __init__(self) -> None:
@@ -74,7 +82,13 @@ def sentry_tunnel(
parts.append(b"\n")
updated_body = b"".join(parts)
- SentryTunnelSession().post(
- url=url, data=updated_body, headers={"Content-Type": "application/x-sentry-envelope"}
- ).raise_for_status()
+ try:
+ SentryTunnelSession().post(
+ url=url,
+ data=updated_body,
+ headers={"Content-Type": "application/x-sentry-envelope"},
+ ).raise_for_status()
+ except RequestException as e:
+ # This logger has been configured, above, to not report to Sentry
+ logger.exception(e)
return HttpResponse(status=200)