Skip to content

Commit

Permalink
fix(django): Fix errors when instrumenting Django cache
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BYK committed Dec 5, 2024
1 parent 5891717 commit 5ea33a4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sentry_sdk/integrations/django/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ def _instrument_call(
span.set_data(SPANDATA.CACHE_HIT, True)
else:
span.set_data(SPANDATA.CACHE_HIT, False)
else:
try:
else: # TODO: We don't handle `get_or_set` which we should
arg_count = len(args)
if arg_count >= 2:
# 'set' command
item_size = len(str(args[1]))
except IndexError:
elif arg_count == 1:
# 'set_many' command
item_size = len(str(args[0]))

Expand Down

0 comments on commit 5ea33a4

Please sign in to comment.