I am experimenting with MeterListener in my application, and using the following code:
public class DiagnosticsService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
using MeterListener meterListener = new();
meterListener.InstrumentPublished = (instrument, listener) =>
{
if (instrument.Meter.Name == "Oracle.ManagedDataAccess.Core")
{
listener.EnableMeasurementEvents(instrument);
Console.WriteLine($"{instrument.Name} registered");
}
};
meterListener.SetMeasurementEventCallback<long>(OnMeasurementRecorded);
meterListener.Start();
try
{
await Task.Delay(-1, stoppingToken);
}
catch(TaskCanceledException)
{
Console.WriteLine("Finish processing");
}
}
public static void OnMeasurementRecorded(Instrument instrument, T measurement, ReadOnlySpan<KeyValuePair<string, object?>> tags, object? state) where T : struct
{
Console.WriteLine($"Measurement recorded: {instrument.Name} - {measurement}");
}
}
I can sucessfuly register all counters published by the Oracle Driver, but the OnMeasurementRecorded is never called.
Am I missing any aditional steps?
My ODP.Net version is 23.8.0 (the connection is accessed throught EF Core 8 provider)
Edit: Fixed the SetMeasurementEventCallback on the example above. The problem persists. Made the same test with other versions of the ODP.Net and OnMeasurementRecorded still not being called.