-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(minimetrics): Fix broken recursion detection #56466
Conversation
if tags is not None: | ||
casted_tags = { | ||
tag_key: str(tag_value) for tag_key, tag_value in tags.items() if tag_value is not None | ||
} | ||
|
||
return cast(Optional[MetricTagsExternal], casted_tags) | ||
return casted_tags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently Optional[MetricsTagsExternal]
causes something odd to happen in typing
and this also raise a recursion error for me:
11:59:28 [ERROR] sentry.errors: Unable to record backend metric
Traceback (most recent call last):
File "/Users/mitsuhiko/Development/sentry/src/sentry/utils/metrics.py", line 133, in incr
backend.incr(key, instance, tags, amount, sample_rate)
File "/Users/mitsuhiko/Development/sentry/src/sentry/metrics/middleware.py", line 133, in incr
return self.inner.incr(key, instance, current_tags, amount, sample_rate)
File "/Users/mitsuhiko/Development/sentry/src/sentry/metrics/minimetrics.py", line 86, in incr
tags=_to_minimetrics_external_metric_tags(tags),
File "/Users/mitsuhiko/Development/sentry/src/sentry/metrics/minimetrics.py", line 18, in _to_minimetrics_external_metric_tags
return cast(Optional[MetricTagsExternal], casted_tags)
File "/Users/mitsuhiko/.pyenv/versions/3.8.12/lib/python3.8/typing.py", line 258, in inner
return cached(*args, **kwds)
File "/Users/mitsuhiko/.pyenv/versions/3.8.12/lib/python3.8/typing.py", line 330, in __hash__
return hash((self._name,))
RecursionError: maximum recursion depth exceeded while calling a Python object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is just that it finally failed recursion on that level, but given that cast()
is just unnecessary runtime overhead, I removed it.
Codecov Report
@@ Coverage Diff @@
## master #56466 +/- ##
=======================================
Coverage 78.65% 78.65%
=======================================
Files 5078 5078
Lines 218270 218270
Branches 36951 36951
=======================================
+ Hits 171676 171678 +2
+ Misses 41052 41051 -1
+ Partials 5542 5541 -1
|
add
can call intometrics.incr
which can go back into minimetrics. This fixes this recursion.