diff --git a/Readme.md b/Readme.md index 5869cf2..8a965f3 100644 --- a/Readme.md +++ b/Readme.md @@ -536,14 +536,25 @@ Integrate OpenTelemetry for observability, including metrics, traces, and loggin app.Run(); ``` 2. Prometheus Endpoints: - - Metrics: `url/above-board/metrics` - - Health Metrics: `url/above-board/metrics/health` -3. Included Features: + - Metrics: `url/above-board/prometheus` + - Health Metrics: `url/above-board/prometheus/health` + +3. OTLP Configuration: + To configure the OTLP exporter, ensure the following entries are present in your appsettings{Environment}.json or as environment variables: + ```json + { + "OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317", + "OTEL_SERVICE_NAME": "OTLP-Example" + } + ``` +4. Included Features: - ASP.NET Core metrics - HTTP client telemetry - Distributed tracing - Logging - Prometheus exporter + - OTLP exporter + - EF Core telemetry ## HealthChecks diff --git a/src/SharedKernel/Extensions/OpenTelemetryExtension.cs b/src/SharedKernel/Extensions/OpenTelemetryExtension.cs index 21384b2..41cd924 100644 --- a/src/SharedKernel/Extensions/OpenTelemetryExtension.cs +++ b/src/SharedKernel/Extensions/OpenTelemetryExtension.cs @@ -3,6 +3,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; +using OpenTelemetry; +using OpenTelemetry.Logs; using OpenTelemetry.Metrics; using OpenTelemetry.Resources; using OpenTelemetry.Trace; @@ -22,28 +24,34 @@ public static WebApplicationBuilder AddOpenTelemetry(this WebApplicationBuilder builder.Services .AddOpenTelemetry() + .UseOtlpExporter() .ConfigureResource(resource => resource.AddService(builder.Environment.ApplicationName)) .WithMetrics(metrics => { metrics.AddRuntimeInstrumentation() .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() - .AddPrometheusExporter(); + .AddPrometheusExporter() + .AddOtlpExporter(); }) .WithTracing(tracing => { tracing.AddAspNetCoreInstrumentation() - .AddHttpClientInstrumentation(); + .AddHttpClientInstrumentation() + .AddEntityFrameworkCoreInstrumentation() + .AddOtlpExporter(); }); + builder.Logging.AddOpenTelemetry(logging => logging.AddOtlpExporter()); + return builder; } public static WebApplication MapPrometheusExporterEndpoints(this WebApplication app) { - app.MapPrometheusScrapingEndpoint($"{EndpointConstants.BasePath}/metrics"); + app.MapPrometheusScrapingEndpoint($"{EndpointConstants.BasePath}/prometheus"); - app.UseHealthChecksPrometheusExporter($"{EndpointConstants.BasePath}/metrics/health", + app.UseHealthChecksPrometheusExporter($"{EndpointConstants.BasePath}/prometheus/health", options => options.ResultStatusCodes[HealthStatus.Unhealthy] = (int)HttpStatusCode.OK); return app; diff --git a/src/SharedKernel/SharedKernel.csproj b/src/SharedKernel/SharedKernel.csproj index f2be50e..186964d 100644 --- a/src/SharedKernel/SharedKernel.csproj +++ b/src/SharedKernel/SharedKernel.csproj @@ -8,13 +8,13 @@ Readme.md Pandatech MIT - 1.0.13 + 1.0.14 Pandatech.SharedKernel Pandatech Shared Kernel Library Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document. https://github.com/PandaTechAM/be-lib-sharedkernel - Language iso code helper added + OpenTelemetry upgrade @@ -43,6 +43,7 @@ + @@ -51,7 +52,7 @@ - +