-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(minimetrics): Add internal recursion protection #57791
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
Changes from all commits
484c36b
37ba7db
7e7fe8b
80d54d3
19f59ae
7ba561c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import sentry_sdk | ||
|
||
try: | ||
from sentry_sdk.metrics import Metric, MetricsAggregator # type: ignore | ||
from sentry_sdk.metrics import Metric, MetricsAggregator, metrics_noop # type: ignore | ||
|
||
have_minimetrics = True | ||
except ImportError: | ||
|
@@ -25,17 +25,22 @@ def patch_sentry_sdk(): | |
real_add = MetricsAggregator.add | ||
real_emit = MetricsAggregator._emit | ||
|
||
@wraps(real_add) | ||
def tracked_add(self, ty, *args, **kwargs): | ||
real_add(self, ty, *args, **kwargs) | ||
@metrics_noop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would honestly fix it in a different way, since this code works under the assumption that the SDK sets internally the thread local. I would honestly implement it differently and more reliably by just adding the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to #57782 but with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't believe the code makes such an assumption as The risk of a second thread local is this one:
I believe if they do not use the same thread local we have paths where only minimetrics protects itself, but not the outer code path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok so it sets also the thread local, I thought it was only checking it and not triggering the function. |
||
def report_tracked_add(ty): | ||
metrics.incr( | ||
key="minimetrics.add", | ||
amount=1, | ||
tags={"metric_type": ty}, | ||
sample_rate=1.0, | ||
) | ||
|
||
@wraps(real_add) | ||
def tracked_add(self, ty, *args, **kwargs): | ||
real_add(self, ty, *args, **kwargs) | ||
report_tracked_add(ty) | ||
|
||
@wraps(real_emit) | ||
@metrics_noop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual fix #2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note here: i want to add a change to the python SDK which protects the manual |
||
def patched_emit(self, flushable_buckets: Iterable[Tuple[int, Dict[Any, Metric]]]): | ||
flushable_metrics = [] | ||
stats_by_type: Any = {} | ||
|
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.
This is the actual fix #1