From 31032a0b18687c056e1486683ecbf1c180be3c31 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:01:36 -0800 Subject: [PATCH] Use static Meter --- .../AspNetCoreMetrics.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreMetrics.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreMetrics.cs index 53e4f8f17ec..14ab42d511b 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreMetrics.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreMetrics.cs @@ -30,6 +30,8 @@ internal sealed class AspNetCoreMetrics : IDisposable internal static readonly string InstrumentationName = AssemblyName.Name; internal static readonly string InstrumentationVersion = AssemblyName.Version.ToString(); + private static readonly Meter InstrumentationMeter = new(InstrumentationName, InstrumentationVersion); + private static readonly HashSet DiagnosticSourceEvents = new() { "Microsoft.AspNetCore.Hosting.HttpRequestIn", @@ -43,12 +45,10 @@ internal sealed class AspNetCoreMetrics : IDisposable => DiagnosticSourceEvents.Contains(eventName); private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber; - private readonly Meter meter; internal AspNetCoreMetrics() { - this.meter = new Meter(InstrumentationName, InstrumentationVersion); - var metricsListener = new HttpInMetricsListener("Microsoft.AspNetCore", this.meter); + var metricsListener = new HttpInMetricsListener("Microsoft.AspNetCore", InstrumentationMeter); this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(metricsListener, this.isEnabled, AspNetCoreInstrumentationEventSource.Log.UnknownErrorProcessingEvent); this.diagnosticSourceSubscriber.Subscribe(); } @@ -57,7 +57,6 @@ internal AspNetCoreMetrics() public void Dispose() { this.diagnosticSourceSubscriber?.Dispose(); - this.meter?.Dispose(); } } #endif