Skip to content

Commit

Permalink
Add upstream URL when sending Photon request exceptions to Sentry (#2509
Browse files Browse the repository at this point in the history
)
  • Loading branch information
krysal authored Jul 3, 2023
1 parent 4fc9ba7 commit a825380
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion api/api/utils/image_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import django_redis
import requests
import sentry_sdk
from sentry_sdk import push_scope, set_context

from api.utils.image_proxy.exception import UpstreamThumbnailException
from api.utils.image_proxy.extension import get_image_extension
Expand Down Expand Up @@ -108,7 +109,19 @@ def get(
if count <= settings.THUMBNAIL_ERROR_INITIAL_ALERT_THRESHOLD or (
count % settings.THUMBNAIL_ERROR_REPEATED_ALERT_FREQUENCY == 0
):
sentry_sdk.capture_exception(exc)
with push_scope() as scope:
set_context(
"upstream_url",
{
"url": upstream_url,
"params": params,
"headers": headers,
},
)
scope.set_tag(
"occurrences", settings.THUMBNAIL_ERROR_REPEATED_ALERT_FREQUENCY
)
sentry_sdk.capture_exception(exc)
if isinstance(exc, requests.exceptions.HTTPError):
tallies.incr(
f"thumbnail_http_error:{domain}:{month}:{exc.response.status_code}:{exc.response.text}"
Expand Down

0 comments on commit a825380

Please sign in to comment.