Adds open telemetry for prometheus

This commit is contained in:
Beau Findlay
2026-02-01 11:56:24 +00:00
parent b8e1bf8467
commit 014fc042a0
2 changed files with 17 additions and 0 deletions

View File

@@ -18,4 +18,10 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.15.0-beta.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.0" />
</ItemGroup>
</Project>

View File

@@ -1,9 +1,18 @@
using BlazorApp.Components;
using OpenTelemetry.Metrics;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents();
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation();
metrics.AddPrometheusExporter();
});
var app = builder.Build();
app.MapGet("/health", () => Results.Ok(new
@@ -12,6 +21,8 @@ app.MapGet("/health", () => Results.Ok(new
timestamp = DateTime.UtcNow
}));
app.MapPrometheusScrapingEndpoint();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", true);