Skip to content

Commit 31fdcfa

Browse files
authored
fix(django): Fix errors when instrumenting Django cache (#3855)
I was testing Spotlight with Sentry and realized things started to get slow and crashy. It looks like sometimes `args` is just an empty array on cache's `_instruments_call` causing lots of exceptions being thrown. This patch fixes that with explicit length checks and also adds a note for the missing instrumentation for `get_or_set` method. This might be related to #2122 and #3300.
1 parent 5891717 commit 31fdcfa

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sentry_sdk/integrations/django/caching.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ def _instrument_call(
7575
span.set_data(SPANDATA.CACHE_HIT, True)
7676
else:
7777
span.set_data(SPANDATA.CACHE_HIT, False)
78-
else:
79-
try:
78+
else: # TODO: We don't handle `get_or_set` which we should
79+
arg_count = len(args)
80+
if arg_count >= 2:
8081
# 'set' command
8182
item_size = len(str(args[1]))
82-
except IndexError:
83+
elif arg_count == 1:
8384
# 'set_many' command
8485
item_size = len(str(args[0]))
8586

0 commit comments

Comments
 (0)