Skip to content

Commit

Permalink
Use static Meter
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla committed Dec 2, 2023
1 parent c5f5dd7 commit 31032a0
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> DiagnosticSourceEvents = new()
{
"Microsoft.AspNetCore.Hosting.HttpRequestIn",
Expand All @@ -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();
}
Expand All @@ -57,7 +57,6 @@ internal AspNetCoreMetrics()
public void Dispose()
{
this.diagnosticSourceSubscriber?.Dispose();
this.meter?.Dispose();
}
}
#endif

0 comments on commit 31032a0

Please sign in to comment.