Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add upstream URL when sending Photon request exceptions to Sentry (#2509)

Krystle Salazara8253809312e
diff --git a/api/api/utils/image_proxy/__init__.py b/api/api/utils/image_proxy/__init__.py
index 2b83eda90..de1c9fd28 100644
--- a/api/api/utils/image_proxy/__init__.py
+++ b/api/api/utils/image_proxy/__init__.py
@@ -9,6 +9,7 @@ from rest_framework.exceptions import UnsupportedMediaType
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
@@ -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}"