dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.25k stars 4.73k forks source link

dotnet.assembly.count Shouldn't Be An UpDown Counter #108566

Open zing321 opened 1 month ago

zing321 commented 1 month ago

Description

I see that dotnet.assembly.count is an up down counter. Is that right? The value that's fed to the counter isn't a delta but the exact assembly count. It's not the only one in System.Runtime that's like that.

Reproduction Steps

Listen to the instrument dotnet.assembly.count via MeterListener and observe the values

Expected behavior

dotnet.assembly.count is an updown counter thus its expected to have values like 1, 2, 3, -1, -2, -3.

Actual behavior

dotnet.assembly.count reports exact numbers such as However 432.

Regression?

No

Known Workarounds

Do not depend on the instrument type instead you must already know that the instrument is actually a normal observable counter with exact values and measure it as such.

Configuration

No response

Other information

No response

maxkatz6 commented 1 month ago

It's not just "up down counter", but actually an "observable up down counter". Observable version is pull based, i.e. it calculates delta only when listener requests for latest data. And this delta is calculated from previously read data. Meaning, if listener pulling rate is low, some changes might be swallowed, like an assembly which was loaded and unloaded in between pulls.

zing321 commented 4 weeks ago

@maxkatz6 Unfortunately what you described is not how it behaves. it just reports the exact value of the info passed to the counter whenever you record observable counters. We can see that reporting the exact value is how ObservableUpDownCounter is implemented here https://github.com/dotnet/runtime/blob/main/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/ObservableUpDownCounter.cs

Other counters outside of System.Runtime such as System.Net.Http's http.client.open_connections behaves as you described.

Say there are 200 assemblies loaded and that hasn't changed since you started the application. whenever you call meterListener.RecordObservableInstruments() it will always report 200 instead of 0 which is what's expected from an ObservableUpDownCounter.

Also imo it should not be an up down counter anyway.