-
Notifications
You must be signed in to change notification settings - Fork 67
/
Program.cs
54 lines (47 loc) · 1.58 KB
/
Program.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Diagnostics.Metrics;
using OpenTelemetry;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Configure the OpenTelemetry SDK for traces and metrics
builder.Services.AddOpenTelemetry()
.UseOtlpExporter()
.ConfigureResource(resourceBuilder =>
{
resourceBuilder
.AddService(serviceName: "getting-started-dotnet",
serviceVersion: typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown");
})
.WithTracing(tracerProviderBuilder =>
{
tracerProviderBuilder
.AddSource(nameof(dotnet))
.AddAspNetCoreInstrumentation();
})
.WithMetrics(meterProviderBuilder =>
{
meterProviderBuilder
.AddMeter(nameof(dotnet))
.AddAspNetCoreInstrumentation()
.AddRuntimeInstrumentation()
.AddView(instrument =>
{
return instrument.GetType().GetGenericTypeDefinition() == typeof(Histogram<>)
? new Base2ExponentialBucketHistogramConfiguration()
: null;
});
});
// Configure the OpenTelemetry SDK for logs
builder.Logging.ClearProviders();
builder.Logging.AddOpenTelemetry(options =>
{
options.IncludeFormattedMessage = true;
options.ParseStateValues = true;
options.IncludeScopes = true;
});
var app = builder.Build();
app.MapControllers();
app.Run();