feat: add OpenTelemetry instrumentation (tracing + metrics + logging)
- OTLP gRPC exporter to 192.168.1.154:4316 - ASP.NET Core, HttpClient, EF Core, Runtime instrumentation - Log export via AddOpenTelemetry logging
This commit is contained in:
parent
54db985fa5
commit
c2d114535d
@ -1,10 +1,20 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using OpenTelemetry.Logs;
|
||||||
using RAG.Api;
|
using RAG.Api;
|
||||||
using RAG.Infrastructure.Persistence;
|
using RAG.Infrastructure.Persistence;
|
||||||
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
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 的具体类型和接口类型
|
// ABP 需要同时注册 ObjectAccessor 的具体类型和接口类型
|
||||||
var appBuilderAccessor = new ObjectAccessor<Microsoft.AspNetCore.Builder.IApplicationBuilder>();
|
var appBuilderAccessor = new ObjectAccessor<Microsoft.AspNetCore.Builder.IApplicationBuilder>();
|
||||||
var webAppAccessor = new ObjectAccessor<Microsoft.AspNetCore.Builder.WebApplication>();
|
var webAppAccessor = new ObjectAccessor<Microsoft.AspNetCore.Builder.WebApplication>();
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<NoWarn>$(NoWarn);NU1902</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -18,6 +19,14 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Volo.Abp.AspNetCore" Version="10.3.0" />
|
<PackageReference Include="Volo.Abp.AspNetCore" Version="10.3.0" />
|
||||||
<PackageReference Include="Volo.Abp.Core" Version="10.3.0" />
|
<PackageReference Include="Volo.Abp.Core" Version="10.3.0" />
|
||||||
|
<PackageReference Include="OpenTelemetry" Version="1.11.2" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.11.2" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.2" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.2" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.1" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.11.1" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.11.0-beta.2" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.11.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using FastEndpoints.Security;
|
using FastEndpoints.Security;
|
||||||
using FastEndpoints.Swagger;
|
using FastEndpoints.Swagger;
|
||||||
|
using OpenTelemetry.Metrics;
|
||||||
|
using OpenTelemetry.Resources;
|
||||||
|
using OpenTelemetry.Trace;
|
||||||
using RAG.Api.Grpc;
|
using RAG.Api.Grpc;
|
||||||
using RAG.Api.Middleware;
|
using RAG.Api.Middleware;
|
||||||
using RAG.Api.Services;
|
using RAG.Api.Services;
|
||||||
@ -23,6 +26,27 @@ public class RAGApiModule : AbpModule
|
|||||||
var services = context.Services;
|
var services = context.Services;
|
||||||
var config = services.GetConfiguration();
|
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
|
// FastEndpoints + Swagger
|
||||||
services.AddFastEndpoints();
|
services.AddFastEndpoints();
|
||||||
services.SwaggerDocument();
|
services.SwaggerDocument();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user