MCPcopy Create free account
hub / github.com/aptabase/aptabase / Extensions

Class Extensions

src/Extensions/TelemetryExtensions.cs:12–108  ·  view source on GitHub ↗

Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry. This project should be referenced by each service project in your solution. To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults

Source from the content-addressed store, hash-verified

10// This project should be referenced by each service project in your solution.
11// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
12public static class Extensions
13{
14 public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder)
15 {
16 builder.ConfigureOpenTelemetry();
17
18 builder.AddDefaultHealthChecks();
19
20 builder.Services.AddServiceDiscovery();
21
22 builder.Services.ConfigureHttpClientDefaults(http =>
23 {
24 // Turn on resilience by default
25 http.AddStandardResilienceHandler();
26
27 // Turn on service discovery by default
28 http.AddServiceDiscovery();
29 });
30
31 return builder;
32 }
33
34 public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder)
35 {
36 builder.Logging.AddOpenTelemetry(logging =>
37 {
38 logging.IncludeFormattedMessage = true;
39 logging.IncludeScopes = true;
40 });
41
42 builder.Services.AddOpenTelemetry()
43 .WithMetrics(metrics =>
44 {
45 metrics.AddAspNetCoreInstrumentation()
46 .AddHttpClientInstrumentation()
47 .AddRuntimeInstrumentation();
48 })
49 .WithTracing(tracing =>
50 {
51 tracing.AddAspNetCoreInstrumentation()
52 // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
53 //.AddGrpcClientInstrumentation()
54 .AddHttpClientInstrumentation();
55 });
56
57 builder.AddOpenTelemetryExporters();
58
59 return builder;
60 }
61
62 private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder)
63 {
64 var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
65
66 if (useOtlpExporter)
67 {
68 builder.Services.AddOpenTelemetry().UseOtlpExporter();
69 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected