Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 12 additions & 4 deletions src/SharedKernel/Extensions/OpenTelemetryExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/SharedKernel/SharedKernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>Pandatech</Authors>
<Copyright>MIT</Copyright>
<Version>1.0.13</Version>
<Version>1.0.14</Version>
<PackageId>Pandatech.SharedKernel</PackageId>
<Title>Pandatech Shared Kernel Library</Title>
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
<Description>Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-sharedkernel</RepositoryUrl>
<PackageReleaseNotes>Language iso code helper added</PackageReleaseNotes>
<PackageReleaseNotes>OpenTelemetry upgrade</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -43,6 +43,7 @@
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.8.0-rc.1"/>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.12" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0"/>
<PackageReference Include="Pandatech.Crypto" Version="4.1.1" />
Expand All @@ -51,7 +52,7 @@
<PackageReference Include="Pandatech.PandaVaultClient" Version="4.0.3" />
<PackageReference Include="Pandatech.RegexBox" Version="3.0.0" />
<PackageReference Include="Pandatech.ResponseCrafter" Version="5.0.3" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.46" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.48" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.1.0" />
</ItemGroup>
Expand Down