-
Notifications
You must be signed in to change notification settings - Fork 9
/
Program.cs
78 lines (67 loc) · 2.33 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Reflection;
using MainSerivce.Data;
using MainService;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<Instrumentor>();
builder.Services.ConfigureHttpClientDefaults(http =>
http.AddStandardResilienceHandler());
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});
void ConfigureResource(ResourceBuilder resource)
{
var assembly = Assembly.GetExecutingAssembly().GetName();
var assemblyVersion = assembly.Version?.ToString() ?? "1.08";
resource.AddService(Instrumentor.ServiceName, serviceVersion: assemblyVersion)
.AddTelemetrySdk()
.AddAttributes(new Dictionary<string, object>
{
["environment.name"] = builder.Environment.EnvironmentName,
["app.group"] = "main"
});
}
builder.Services.AddOpenTelemetry()
.ConfigureResource(ConfigureResource)
.WithTracing(tracerProviderBuilder =>
tracerProviderBuilder
.AddSource(Instrumentor.ServiceName)
.AddAspNetCoreInstrumentation(opts =>
{
opts.Filter = ctx =>
{
var ignore = new[]
{
"/_blazor", "/_framework", ".css",
"/css", "/favicon"
};
return !ignore.Any(s => ctx.Request.Path.Value!.Contains(s));
};
})
.AddHttpClientInstrumentation())
.WithMetrics(metricsProviderBuilder =>
metricsProviderBuilder
.AddMeter(Instrumentor.ServiceName)
.AddRuntimeInstrumentation()
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation())
.UseOtlpExporter();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<IWeatherService, RemoteWeatherService>();
builder.Services.AddHttpClient("WeatherService", client =>
{
client.BaseAddress = new Uri("http://localhost:5006");
client.DefaultRequestHeaders.UserAgent.ParseAdd("MainService");
});
var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();