Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help configuring MeterListener for .net counters

user8984907May 23 2025 — edited May 23 2025

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.

This post has been answered by user8984907 on May 23 2025
Jump to Answer
Comments
Post Details
Added on May 23 2025
1 comment
117 views