- 
                Notifications
    You must be signed in to change notification settings 
- Fork 381
Enable UpDownCounter For Dotnet-Counters and Dotnet-Monitor #3849
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 4 commits
89d9814
              e0cfa8f
              281f7c5
              2a04557
              45029f1
              94a5a3d
              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 | 
|---|---|---|
|  | @@ -90,6 +90,10 @@ public static bool TryGetCounterPayload(this TraceEvent traceEvent, CounterFilte | |
| { | ||
| HandleCounterRate(traceEvent, filter, sessionId, out payload); | ||
| } | ||
| else if (traceEvent.EventName == "UpDownCounterRateValuePublished") | ||
| { | ||
| HandleUpDownCounterValue(traceEvent, filter, sessionId, out payload); | ||
| } | ||
| else if (traceEvent.EventName == "TimeSeriesLimitReached") | ||
| { | ||
| HandleTimeSeriesLimitReached(traceEvent, sessionId, out payload); | ||
|  | @@ -188,6 +192,44 @@ private static void HandleCounterRate(TraceEvent traceEvent, CounterFilter filte | |
| } | ||
| } | ||
|  | ||
| private static void HandleUpDownCounterValue(TraceEvent traceEvent, CounterFilter filter, string sessionId, out ICounterPayload payload) | ||
| { | ||
| payload = null; | ||
|  | ||
| string payloadSessionId = (string)traceEvent.PayloadValue(0); | ||
|  | ||
| if (payloadSessionId != sessionId || traceEvent.Version < 1) // Version 1 added the value field. | ||
| { | ||
| return; | ||
| } | ||
|  | ||
| string meterName = (string)traceEvent.PayloadValue(1); | ||
| //string meterVersion = (string)obj.PayloadValue(2); | ||
| string instrumentName = (string)traceEvent.PayloadValue(3); | ||
| string unit = (string)traceEvent.PayloadValue(4); | ||
| string tags = (string)traceEvent.PayloadValue(5); | ||
| _ = (string)traceEvent.PayloadValue(6); // Not currently using rate for UpDownCounters. | ||
| string valueText = (string)traceEvent.PayloadValue(7); | ||
|  | ||
| if (!filter.IsIncluded(meterName, instrumentName)) | ||
| { | ||
| return; | ||
| } | ||
|  | ||
| if (double.TryParse(valueText, NumberStyles.Number | NumberStyles.Float, CultureInfo.InvariantCulture, out double value)) | ||
| { | ||
| // UpDownCounter reports the value, not the rate - this is different than how Counter behaves. | ||
| 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. If you think dotnet-monitor would be improved by reporting the value rather than rate for Counter I'd say go for it (in a different PR). There might be compat issues to contend with, but over time my perspective has been shifting towards rate being useful for Counter UI visualization for users, but at every stage prior to that point the absolute counter value appears easier to work with. | ||
| payload = new UpDownCounterPayload(meterName, instrumentName, null, unit, tags, value, traceEvent.TimeStamp); | ||
|  | ||
| } | ||
| else | ||
| { | ||
| // for observable instruments we assume the lack of data is meaningful and remove it from the UI | ||
| // this happens when the ObservableUpDownCounter callback function throws an exception. | ||
|         
                  kkeirstead marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| payload = new CounterEndedPayload(meterName, instrumentName, traceEvent.TimeStamp); | ||
| } | ||
| } | ||
|  | ||
| private static void HandleHistogram(TraceEvent obj, CounterFilter filter, string sessionId, out ICounterPayload payload) | ||
| { | ||
| payload = null; | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.