diff --git a/src/RAG.Api/Program.cs b/src/RAG.Api/Program.cs index b56c81c..c44f5db 100644 --- a/src/RAG.Api/Program.cs +++ b/src/RAG.Api/Program.cs @@ -1,10 +1,20 @@ using Microsoft.EntityFrameworkCore; +using OpenTelemetry.Logs; using RAG.Api; using RAG.Infrastructure.Persistence; using Volo.Abp.DependencyInjection; var builder = WebApplication.CreateBuilder(args); +// OTel 日志导出 +builder.Logging.AddOpenTelemetry(logging => +{ + logging.AddOtlpExporter(options => + { + options.Endpoint = new Uri("http://192.168.1.154:4316"); + }); +}); + // ABP 需要同时注册 ObjectAccessor 的具体类型和接口类型 var appBuilderAccessor = new ObjectAccessor(); var webAppAccessor = new ObjectAccessor(); diff --git a/src/RAG.Api/RAG.Api.csproj b/src/RAG.Api/RAG.Api.csproj index a7e6524..0bd1bc7 100644 --- a/src/RAG.Api/RAG.Api.csproj +++ b/src/RAG.Api/RAG.Api.csproj @@ -4,6 +4,7 @@ net10.0 enable enable + $(NoWarn);NU1902 @@ -18,6 +19,14 @@ + + + + + + + + diff --git a/src/RAG.Api/RAGApiModule.cs b/src/RAG.Api/RAGApiModule.cs index 8904b33..677c898 100644 --- a/src/RAG.Api/RAGApiModule.cs +++ b/src/RAG.Api/RAGApiModule.cs @@ -1,6 +1,9 @@ using FastEndpoints; using FastEndpoints.Security; using FastEndpoints.Swagger; +using OpenTelemetry.Metrics; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; using RAG.Api.Grpc; using RAG.Api.Middleware; using RAG.Api.Services; @@ -23,6 +26,27 @@ public class RAGApiModule : AbpModule var services = context.Services; var config = services.GetConfiguration(); + // OpenTelemetry + services.AddOpenTelemetry() + .ConfigureResource(r => r + .AddService(serviceName: "rag-backend", serviceVersion: "1.0.0")) + .WithTracing(tracing => tracing + .AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation() + .AddEntityFrameworkCoreInstrumentation() + .AddOtlpExporter(options => + { + options.Endpoint = new Uri("http://192.168.1.154:4316"); + })) + .WithMetrics(metrics => metrics + .AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation() + .AddRuntimeInstrumentation() + .AddOtlpExporter((exporterOptions, readerOptions) => + { + exporterOptions.Endpoint = new Uri("http://192.168.1.154:4316"); + })); + // FastEndpoints + Swagger services.AddFastEndpoints(); services.SwaggerDocument();