-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Metrics APIs Additions #86567
Metrics APIs Additions #86567
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
...Extensions.Diagnostics.Abstractions/src/Microsoft.Extensions.Diagnostics.Abstractions.csproj
Show resolved
Hide resolved
_cachedMeters.Add(options.Name, meterList); | ||
} | ||
|
||
Meter m = new Meter(options.Name, options.Version, options.Tags, scope: this); |
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.
Weren't we going to use a subclassed Meter who's exposed Dispose was a nop?
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.
I will investigate the disposal issue further to determine the best possible solution. I'll track the issue and will link it here.
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.
Ok. If we don't end up changing this, we need to change the name of the method. Calling it Create and returning something that's IDisposable but then telling people in docs not to Dispose it will lead to a pit of failure.
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.
I opened #86592
src/libraries/Microsoft.Extensions.Diagnostics/src/DefaultMeterFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics/src/DefaultMeterFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics/src/DefaultMeterFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics/src/DefaultMeterFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics/src/MetricsServiceExtensions.cs
Outdated
Show resolved
Hide resolved
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/InstrumentRecorder.cs
Outdated
Show resolved
Hide resolved
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/InstrumentRecorder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs
Outdated
Show resolved
Hide resolved
...oft.Extensions.Diagnostics.Abstractions/ref/Microsoft.Extensions.Diagnostics.Abstractions.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/IMeterFactory.cs
Outdated
Show resolved
Hide resolved
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/InstrumentRecorder.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics/src/DefaultMeterFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics/src/DefaultMeterFactory.cs
Outdated
Show resolved
Hide resolved
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/InstrumentRecorder.cs
Outdated
Show resolved
Hide resolved
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/InstrumentRecorder.cs
Outdated
Show resolved
Hide resolved
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/InstrumentRecorder.cs
Outdated
Show resolved
Hide resolved
{ | ||
Name = name ?? throw new ArgumentNullException(nameof(name)); | ||
Version = version; | ||
if (tags is not null) | ||
{ | ||
Tags = new List<KeyValuePair<string, object?>>(tags); |
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.
The consumer could do:
((List<...>)meter.Tags).Add(...);
Would that mess anything up?
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.
Users doing that will be missing up with themselves. It is not good to depend on the internal implementation anyway. But even if they do that in this case, it will not cause crashes or terrible things. Will just be updating a list that not supposed to be mutated.
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs
Outdated
Show resolved
Hide resolved
...Extensions.Diagnostics.Abstractions/src/Microsoft.Extensions.Diagnostics.Abstractions.csproj
Show resolved
Hide resolved
...Extensions.Diagnostics.Abstractions/ref/Microsoft.Extensions.Diagnostics.Abstractions.csproj
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics/ref/Microsoft.Extensions.Diagnostics.csproj
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics/src/Microsoft.Extensions.Diagnostics.csproj
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Metrics/IMeterFactory.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Diagnostics/src/Metrics/DefaultMeterFactory.cs
Show resolved
Hide resolved
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.
mostly looked good, a few comments inline
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Instrument.cs
Outdated
Show resolved
Hide resolved
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/InstrumentRecorder.cs
Outdated
Show resolved
Hide resolved
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/InstrumentRecorder.cs
Outdated
Show resolved
Hide resolved
|
||
if (_isObservableInstrument) | ||
{ | ||
_meterListener.RecordObservableInstruments(); |
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.
Oh I missed this. At some point in the past I thought there was an explicit RecordObservableInstrument() API. Doing it this way feels weird to me because now GetMeasurements() is mutating the list every time it is called. I think the design would be better if we have a separate explicit API that records observable instruments. For example imagine a user wants to capture measurements at several points, then verify them:
//arrange
using recorder = new InstrumentRecorder<int>(observableInstrument);
//act
SetState1();
recorder.GetMeasurements();
SetState2();
recorder.GetMeasurements();
SetState3();
recorder.GetMeasurements();
//assert
//I want to confirm that all three cases produced a measurement.
//but I can't use GetMeasurements() here because it changes the count to 4.
Assert.Equals(3, recorder.GetMeasurements().Length);
Users could of course workaround it by saving a snapshot of the measurements earlier, but needing to treat the API differently for observable and non-observable instruments feels awkward. Having API called 'GetXXX' change the thing it is getting also seems like it wouldn't align with our naming rules.
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.
I'll keep whatever I have in this PR and then we can talk about this one to know if we really need a new API.
{ | ||
Name = name ?? throw new ArgumentNullException(nameof(name)); | ||
Version = version; | ||
if (tags is not null) | ||
{ | ||
Tags = new List<KeyValuePair<string, object?>>(tags); |
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.
Any reason to use List rather than array? We should never modify this collection in the future. Also I'd suggest we sort it.
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.
I changed the List to Array. I'll address the tags sorting and tags insensitive comparisons in a separate PR when addressing #86614.
Fixes #77514