-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
93 lines (78 loc) · 3.01 KB
/
Program.cs
File metadata and controls
93 lines (78 loc) · 3.01 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using ExampleOpenTelemetryMongoDB.Business;
using MongoDB.Driver;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddOpenTelemetry()
.WithTracing(tracerProviderBuilder =>
{
tracerProviderBuilder
.AddSource("MyAspNetService")
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyAspNetService"))
.AddHttpClientInstrumentation()
.AddAspNetCoreInstrumentation(options =>
{
//options.RecordException = true; // Record exceptions in traces
options.EnrichWithHttpRequest = (activity, request) =>
{
activity.SetTag("http.request.query_string", request.QueryString.ToString());
};
})
.AddOtlpExporter(options =>
{
options.Endpoint = new Uri("http://localhost:4317"); // Adjust the endpoint as needed
options.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
});
})
.WithMetrics(metricProviderBuilder =>
{
metricProviderBuilder
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyAspNetService"))
.AddMeter(
"MongoDB.Driver",
"Microsoft.AspNetCore.Hosting",
"Microsoft.AspNetCore.Server.Kestrel",
"System.Runtime",
"System.Diagnostics.Process",
"System.Net.Http"
)
.AddOtlpExporter(options =>
{
options.Endpoint = new Uri("http://localhost:4317"); // Adjust the endpoint as needed
options.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
});
});
builder.Logging.AddOpenTelemetry(options =>
{
options.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyAspNetService"));
options.IncludeScopes = true; // Wenn du Scopes in Logs willst
options.ParseStateValues = true;
options.IncludeFormattedMessage = true;
// OTLP Exporter (für Collector, Grafana, etc.)
options.AddOtlpExporter(opt =>
{
opt.Endpoint = new Uri("http://localhost:4317"); // oder 4318 für HTTP, je nach Collector
// opt.Protocol = OtlpExportProtocol.Grpc; // Default: gRPC
});
});
builder.Services.AddSingleton<IMongoClient>(sp =>
new MongoClient("mongodb://localhost:27017"));
builder.Services.AddSingleton<WeatherForecastBusiness>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();