-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
MeterListener can't listen to RuntimeMetrics #110252
Comments
Seems to be working alright on .NET 9: using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Text;
using System.Threading;
namespace Runtime110252
{
class Program
{
static void Main()
{
using (var listener = new MeterListener())
{
listener.SetMeasurementEventCallback<int>(Measure);
listener.SetMeasurementEventCallback<long>(Measure);
listener.SetMeasurementEventCallback<float>(Measure);
listener.SetMeasurementEventCallback<double>(Measure);
static void Measure<T>(Instrument instrument, T measurement, ReadOnlySpan<KeyValuePair<string, object?>> tags, object? state)
{
var sb = new StringBuilder();
sb.Append($"Measured {typeof(T).Name}: {measurement}");
foreach (var tag in tags)
{
sb.Append($" [{tag.Key}={tag.Value}]");
}
Console.WriteLine(sb);
}
listener.InstrumentPublished = (instrument, listener) =>
{
Console.WriteLine($"InstrumentPublished: {instrument.Name}");
if (instrument.Name == "dotnet.gc.collections")
{
listener.EnableMeasurementEvents(instrument);
}
};
listener.Start();
while (true)
{
Thread.Sleep(TimeSpan.FromSeconds(1));
GC.Collect();
Console.WriteLine("Recording observable instruments.");
listener.RecordObservableInstruments();
}
}
}
}
}
|
"dotnet.gc.collections" is set up as an observable counter here: Lines 32 to 36 in 9d5a6a9
So, verify that your code calls MeterListener.RecordObservableInstruments. The InstrumentPublished delegate is called during MeterListener.Start. |
Thanks for the help! The issue was that |
Description
The constructor of
MeterListener
already publishes runtime metrics likedotnet.gc.collections
. So runtime metrics can never be listened to by MeterListener.Reproduction Steps
Expected behavior
We would like a way to listen to runtime metrics like
dotnet.gc.collections
.Actual behavior
Runtime metrics are published before
MeterListener
can listen to them.Regression?
No response
Known Workarounds
No response
Configuration
tested on dotnet 9.0 on mac-arm64
Other information
No response
The text was updated successfully, but these errors were encountered: