forked from open-telemetry/opentelemetry-dotnet-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAspNetInstrumentation.cs
More file actions
51 lines (42 loc) · 1.91 KB
/
AspNetInstrumentation.cs
File metadata and controls
51 lines (42 loc) · 1.91 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
using System.Diagnostics;
using System.Diagnostics.Metrics;
using System.Reflection;
using OpenTelemetry.Instrumentation.AspNet.Implementation;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Instrumentation.AspNet;
/// <summary>
/// Asp.Net Requests instrumentation.
/// </summary>
internal sealed class AspNetInstrumentation : IDisposable
{
public static readonly AspNetInstrumentation Instance = new();
public static readonly Assembly Assembly = typeof(HttpInListener).Assembly;
public static readonly AssemblyName AssemblyName = Assembly.GetName();
public static readonly string MeterName = AssemblyName.Name!;
public static readonly string ActivitySourceName = AssemblyName.Name;
public static readonly Meter Meter = new(MeterName, Assembly.GetPackageVersion());
public static readonly ActivitySource ActivitySource = new(ActivitySourceName, Assembly.GetPackageVersion());
public static readonly Histogram<double> HttpServerDuration = Meter.CreateHistogram(
"http.server.request.duration",
unit: "s",
description: "Duration of HTTP server requests.",
advice: new InstrumentAdvice<double> { HistogramBucketBoundaries = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10] });
public readonly InstrumentationHandleManager HandleManager = new();
private readonly HttpInListener httpInListener;
/// <summary>
/// Initializes a new instance of the <see cref="AspNetInstrumentation"/> class.
/// </summary>
private AspNetInstrumentation()
{
this.httpInListener = new();
}
public AspNetTraceInstrumentationOptions TraceOptions { get; set; } = new();
public AspNetMetricsInstrumentationOptions MetricOptions { get; set; } = new();
/// <inheritdoc/>
public void Dispose()
{
this.httpInListener?.Dispose();
}
}