// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
namespace Examples.AspNetCore;
using System.Diagnostics;
using System.Diagnostics.Metrics;
///
/// It is recommended to use a custom type to hold references for
/// ActivitySource and Instruments. This avoids possible type collisions
/// with other components in the DI container.
///
public sealed class InstrumentationSource : IDisposable
{
internal const string ActivitySourceName = "Examples.AspNetCore";
internal const string MeterName = "Examples.AspNetCore";
private readonly Meter meter;
public InstrumentationSource()
{
string? version = typeof(InstrumentationSource).Assembly.GetName().Version?.ToString();
this.ActivitySource = new ActivitySource(ActivitySourceName, version);
this.meter = new Meter(MeterName, version);
this.FreezingDaysCounter = this.meter.CreateCounter("weather.days.freezing", description: "The number of days where the temperature is below freezing");
}
public ActivitySource ActivitySource { get; }
public Counter FreezingDaysCounter { get; }
public void Dispose()
{
this.ActivitySource.Dispose();
this.meter.Dispose();
}
}