-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Added StartTimer extension method to IMetricAggregator #3075
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #3075 +/- ##
==========================================
- Coverage 76.42% 76.41% -0.01%
==========================================
Files 351 351
Lines 13263 13275 +12
Branches 2646 2646
==========================================
+ Hits 10136 10144 +8
- Misses 2450 2452 +2
- Partials 677 679 +2 ☔ View full report in Codecov by Sentry. |
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.
That looks much nicer to use! Thanks!
Remind me again why isn't Metrics on the Hub instead? That's where we keep all state last I saw
That's where the scope lives and where other state lives too like session state I believe, no?
Makes sense to be |
I can't find the old conversation (too many threads on the original PR and it's really hard to search in resolved conversations). However, basically it's on the SentryClient as that's where the BackgroundWorker lives... and the aggregator is very similar to the BackgroundWorker. It also doesn't have any dependencies on the Hub - all it needs is a way to send metrics and a way to send code locations (which are two methods on
Kind of... it's a bit of a mixed bag. The Scope really lives in the sentry-dotnet/src/Sentry/Internal/SentryScopeManager.cs Lines 12 to 16 in 941d9dc
So the Scope state is loosely and indirectly associated with the SentryClient... although normally as an AsyncLocal - unless we're in Global mode - so arguably it's tied to the Thread rather than either the Hub or the Client. The ConfigureScope API that is used to read/mutate this lives on the Hub though... so in that respect it feels like a Hub thing. For Session state, both the Hub and the SentryClient hold references to this: sentry-dotnet/src/Sentry/Internal/Hub.cs Line 50 in 2a41c48
sentry-dotnet/src/Sentry/SentryClient.cs Line 54 in 2a41c48
Although when using a Hub, the With the current design, you can also do everything you want to for Metrics via the Hub as well: sentry-dotnet/src/Sentry/Internal/Hub.cs Line 24 in 2a41c48
That's because all of the functionality related to metrics is pretty much encapsulated in the MetricAggregator... the only exception being the functionality to send those metrics to Sentry (which obviously should be a SentryClient thing). We could have the MetricAggregator take a hard dependency on IHub (so that you couldn't send metrics without a Hub)... At the moment, you could technically use Metrics and SentryClient independently (without any Hub)... although with this PR the |
This has already been addressed now.
Resolves #3074
The API for timings has changed from :
... to:
Unfortunately that trivial change to the API interface required quite a bit of refactoring under the hood. The
Timing
class needs anIHub
to create a transaction/span for the timing so we had to move the mainMetricAggregator
fromISentryClient
toIHub
and injectIHub
as a dependency (to enable the creation of transactions).Previously, when it was on SentryClient, the CaptureMetrics and CaptureCodeLocations methods (also on SentryClient) could be internal... because they were only ever referenced from the Client.
Now, with everything on the Hub, the Hub needs to call those methods so they have to be on the ISentryClient interface, which means they have to be public... and so do all of the types used as parameters to those methods.
We have been able to make the
Timing
class internal now though, at least. 😜