From 7fa0dfdcada16c69b791000883ddddea04305fdc Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 31 May 2025 19:57:46 +0800 Subject: [PATCH] :arrow_heavy_plus: Add OpenTelemetry --- .../DysonNetwork.Sphere.csproj | 5 +++++ DysonNetwork.Sphere/Program.cs | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/DysonNetwork.Sphere/DysonNetwork.Sphere.csproj b/DysonNetwork.Sphere/DysonNetwork.Sphere.csproj index b8da08a..53bf0a7 100644 --- a/DysonNetwork.Sphere/DysonNetwork.Sphere.csproj +++ b/DysonNetwork.Sphere/DysonNetwork.Sphere.csproj @@ -49,6 +49,11 @@ + + + + + diff --git a/DysonNetwork.Sphere/Program.cs b/DysonNetwork.Sphere/Program.cs index 60cfa41..8f56004 100644 --- a/DysonNetwork.Sphere/Program.cs +++ b/DysonNetwork.Sphere/Program.cs @@ -29,6 +29,8 @@ using Microsoft.Extensions.Options; using Microsoft.OpenApi.Models; using NodaTime; using NodaTime.Serialization.SystemTextJson; +using OpenTelemetry.Metrics; +using OpenTelemetry.Trace; using Prometheus; using Prometheus.DotNetRuntime; using Prometheus.SystemMetrics; @@ -51,6 +53,7 @@ builder.WebHost.ConfigureKestrel(options => // Configure metrics +// Prometheus builder.Services.UseHttpClientMetrics(); builder.Services.AddHealthChecks(); builder.Services.AddSystemMetrics(); @@ -58,6 +61,24 @@ builder.Services.AddPrometheusEntityFrameworkMetrics(); builder.Services.AddPrometheusAspNetCoreMetrics(); builder.Services.AddPrometheusHttpClientMetrics(); +// OpenTelemetry +builder.Services.AddOpenTelemetry() + .WithTracing(tracing => + { + tracing + .AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation() + .AddOtlpExporter(); + }) + .WithMetrics(metrics => + { + metrics + .AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation() + .AddRuntimeInstrumentation() + .AddOtlpExporter(); + }); + // Add services to the container. builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");