feat: add OpenTelemetry support for monitoring
All checks were successful
Build and Deploy Docker Container / build-and-deploy (push) Successful in 4m21s
All checks were successful
Build and Deploy Docker Container / build-and-deploy (push) Successful in 4m21s
This commit is contained in:
@@ -45,6 +45,11 @@
|
||||
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="9.0.8" />
|
||||
<PackageReference Include="Mirea.Tools.Schedule.Parser" Version="1.2.7" />
|
||||
<PackageReference Include="Mirea.Tools.Schedule.WebParser" Version="1.0.7" />
|
||||
<PackageReference Include="OpenTelemetry" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.12.0" />
|
||||
<PackageReference Include="QRCoder" Version="1.6.0" />
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
|
@@ -20,7 +20,11 @@ using Mirea.Api.Endpoint.Configuration.Validation;
|
||||
using Mirea.Api.Endpoint.Configuration.Validation.Validators;
|
||||
using Mirea.Api.Security.Services;
|
||||
using OfficeOpenXml;
|
||||
using OpenTelemetry.Exporter;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Resources;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Mirea.Api.Endpoint;
|
||||
@@ -118,6 +122,34 @@ public class Program
|
||||
builder.Services.AddDataProtection()
|
||||
.PersistKeysToFileSystem(new DirectoryInfo(PathBuilder.Combine("DataProtection")));
|
||||
|
||||
builder.Host.ConfigureServices((context, services) =>
|
||||
{
|
||||
var config = context.Configuration.Get<GeneralConfig>()?.LogSettings;
|
||||
|
||||
if (string.IsNullOrEmpty(config?.OpenTelemetryEndpoint)
|
||||
|| string.IsNullOrEmpty(config.OpenTelemetryServiceName))
|
||||
return;
|
||||
|
||||
services.AddOpenTelemetry()
|
||||
.WithMetrics(metrics =>
|
||||
{
|
||||
metrics
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddRuntimeInstrumentation()
|
||||
.SetResourceBuilder(ResourceBuilder.CreateDefault()
|
||||
.AddService(serviceName: config.OpenTelemetryServiceName)
|
||||
.AddAttributes([
|
||||
new KeyValuePair<string, object>("deployment.environment", context.HostingEnvironment.EnvironmentName),
|
||||
new KeyValuePair<string, object>("host.name", Environment.MachineName)
|
||||
]))
|
||||
.AddOtlpExporter(options =>
|
||||
{
|
||||
options.Endpoint = new Uri(config.OpenTelemetryEndpoint);
|
||||
options.Protocol = OtlpExportProtocol.Grpc;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseForwardedHeaders();
|
||||
|
Reference in New Issue
Block a user