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

This prevents failure to submit a client-side Sentry trace from
turning into a server-side client trace.  If Sentry is down, we merely
log the error to our error logs and carry on.
This commit is contained in:
Alex Vandiver 2023-10-11 05:43:49 +00:00 committed by Tim Abbott
parent f2f6f6c48c
commit 9519945dc0
1 changed files with 17 additions and 3 deletions

View File

@ -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)