diff --git a/Endpoint/Endpoint.csproj b/Endpoint/Endpoint.csproj
index f5bea67..89be01c 100644
--- a/Endpoint/Endpoint.csproj
+++ b/Endpoint/Endpoint.csproj
@@ -45,6 +45,11 @@
+
+
+
+
+
diff --git a/Endpoint/Program.cs b/Endpoint/Program.cs
index 643e494..7edc3b9 100644
--- a/Endpoint/Program.cs
+++ b/Endpoint/Program.cs
@@ -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()?.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("deployment.environment", context.HostingEnvironment.EnvironmentName),
+ new KeyValuePair("host.name", Environment.MachineName)
+ ]))
+ .AddOtlpExporter(options =>
+ {
+ options.Endpoint = new Uri(config.OpenTelemetryEndpoint);
+ options.Protocol = OtlpExportProtocol.Grpc;
+ });
+ });
+ });
+
var app = builder.Build();
app.UseForwardedHeaders();