Repository navigation
Spike: Capture well known EventSource counters - #3100
Closed
jamescrosswell wants to merge 14 commits into
Closed
jamescrosswell wants to merge 14 commits into
jamescrosswell wants to merge 14 commits into
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #3100 +/- ##
==========================================
- Coverage 76.87% 75.66% -1.22%
==========================================
Files 357 361 +4
Lines 13466 13558 +92
Branches 2671 2684 +13
==========================================
- Hits 10352 10258 -94
- Misses 2435 2623 +188
+ Partials 679 677 -2 ☔ View full report in Codecov by Sentry. |
…e all CounterEvents
Collaborator
Author
|
Discussed with @bitsandfoxes and we agreed to put this on pause for a bit until the Metrics capability in Sentry itself is a bit more mature. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #734
EventSource based metrics are a bit different to the OpenTelemetry metrics (and Sentry Metrics), so some consideration needs to be given to the API.
Initially what I've built is quite naive. You can define one or more EventSourceMatcher objects that are used to define which EventSources should be captured by our listener. The matchers consist of a
SubstringOrRegExexpression that matches against theEventSource.Nameand also a couple of other filters (forLeveland something calledEventKeywords, which is a flags enum) that will be applied to the listener as well):sentry-dotnet/src/Sentry/Internal/SystemDiagnosticsEventSourceListener.cs
Lines 58 to 62 in bbde463
The
Arguments.Valuesupplied above configures events to be captured every 10 seconds, which aligns with our bucketing strategy... this would be one way to ensure we don't overcount metrics which are already pre-aggregated in the EventCounter.Challenges
So far, so good. Where our implementation is a bit naive however is when we report the metrics to Sentry. This happens in the
OnEventWrittenmethod of our listener:sentry-dotnet/src/Sentry/Internal/SystemDiagnosticsEventSourceListener.cs
Lines 76 to 96 in bbde463
There are a couple of challenges with this implementation.
Firstly, it assumes every Counter will be an incrementing counter and that the increment count will always be
1. This is rarely the case.Secondly, most of the interesting data reported by counters is sent in the EventWrittenEventArgs.Payload property... this is unfortunately a
ReadOnlyCollection<object?>?so, yeah, not strongly typed and specific to each EventCounter.Potential Solution
Whilst our current implementation of the
OnEventWrittenmethod might work for some EventCounters, other counters will need to be handled differently. Effectively we have one "EventCounterProcessor" that could be registered to process certain counters for which it was appropriate, but we really need to allow SDK users to supply their own EventCounterProcessors (to handle whatever counters they might want to create themselves) and we should probably implement various built in processors to handle all of the (useful) Well Known counters.For example, the code below gives a feel for how the
System.Net.Sockets[bytes-sent]Eventcounter might be parsed (this code isn't very resilient but demonstrates how we'd need to pull info out of the Payload):That particular counter stores a bunch of stuff as an
IDictionary<string, object>in the payload... with a bit of grunt work we could build some logic to pull all the useful info out and report it to Sentry... we could then encapsulate that logic in a processor which would (hopefully) be able to be reused with other EventCounters that stored their payloads similarly (and differed only in name).Alternatives
It looks like there's an OpenTelemetry wrapper around counters... perhaps we could leverage this?