forked from open-telemetry/opentelemetry-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Instrumentation.cs
37 lines (30 loc) · 1.21 KB
/
Instrumentation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
namespace Examples.AspNetCore;
using System.Diagnostics;
using System.Diagnostics.Metrics;
/// <summary>
/// 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.
/// </summary>
public class Instrumentation : IDisposable
{
internal const string ActivitySourceName = "Examples.AspNetCore";
internal const string MeterName = "Examples.AspNetCore";
private readonly Meter meter;
public Instrumentation()
{
string? version = typeof(Instrumentation).Assembly.GetName().Version?.ToString();
this.ActivitySource = new ActivitySource(ActivitySourceName, version);
this.meter = new Meter(MeterName, version);
this.FreezingDaysCounter = this.meter.CreateCounter<long>("weather.days.freezing", description: "The number of days where the temperature is below freezing");
}
public ActivitySource ActivitySource { get; }
public Counter<long> FreezingDaysCounter { get; }
public void Dispose()
{
this.ActivitySource.Dispose();
this.meter.Dispose();
}
}