Update sentry-sdk requirement from ==1.45.* to ==2.5.* (#4176)

* Update sentry-sdk requirement from ==1.45.* to ==2.3.*

* Review notes
This commit is contained in:
Raphael Michel
2024-06-10 16:25:08 +02:00
committed by GitHub
parent 8bc16af36e
commit ab576bb643
3 changed files with 14 additions and 60 deletions

View File

@@ -19,60 +19,13 @@
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
#
import re
import weakref
from collections import OrderedDict
from celery.exceptions import Retry
from sentry_sdk import Hub
from sentry_sdk.integrations import django as djangosentry
from sentry_sdk.utils import capture_internal_exceptions
MASK = '*' * 8
KEYS = frozenset([
'password',
'secret',
'passwd',
'authorization',
'api_key',
'apikey',
'sentry_dsn',
'access_token',
'session',
])
VALUES_RE = re.compile(r'^(?:\d[ -]*?){13,16}$')
def scrub_data(data):
if isinstance(data, dict):
for k, v in data.items():
if isinstance(k, bytes):
key = k.decode('utf-8', 'replace')
else:
key = k
key = key.lower()
data[k] = scrub_data(v)
for blk in KEYS:
if blk in key:
data[k] = MASK
elif isinstance(data, list):
for i, l in enumerate(list(data)):
data[i] = scrub_data(l)
elif isinstance(data, str):
if '=' in data:
# at this point we've assumed it's a standard HTTP query
# or cookie
if '&' in data:
delimiter = '&'
else:
delimiter = ';'
qd = scrub_data(OrderedDict(e.split('=', 1) if '=' in e else (e, None) for e in data.split(delimiter)))
return delimiter.join((k + '=' + v if v is not None else k) for k, v in qd.items())
if VALUES_RE.match(data):
return MASK
return data
def _make_event_processor(weak_request, integration):
def event_processor(event, hint):
@@ -82,8 +35,6 @@ def _make_event_processor(weak_request, integration):
with capture_internal_exceptions():
djangosentry._set_user_info(request, event)
request_info = event.setdefault("request", {})
request_info["cookies"] = dict(request.COOKIES)
# Sentry's DjangoIntegration already sets the transaction, but it gets confused by our multi-domain stuff
# where the URL resolver changes in the middleware stack. Additionally, we'd like to get the method.
@@ -96,15 +47,6 @@ def _make_event_processor(weak_request, integration):
request.method,
url
)
# We want to scrub data not only from the request, but from traceback frames as well!
scrub_data(event.get("request", {}))
if 'exception' in event:
exc = event.get("exception", {})
for val in exc.get('values', []):
stack = val.get('stacktrace', {})
for frame in stack.get('frames', []):
scrub_data(frame['vars'])
return event
return event_processor