From f4dddbe7dac864a6e8ab2be149200b066f2ccc4d Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Tue, 28 Jun 2022 06:08:46 -0700 Subject: [PATCH] Add runtime metrics to example aspnet core app (#3408) --- examples/AspNetCore/Examples.AspNetCore.csproj | 1 + examples/AspNetCore/Program.cs | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/AspNetCore/Examples.AspNetCore.csproj b/examples/AspNetCore/Examples.AspNetCore.csproj index a6ce0375535..d92150ac7f8 100644 --- a/examples/AspNetCore/Examples.AspNetCore.csproj +++ b/examples/AspNetCore/Examples.AspNetCore.csproj @@ -8,6 +8,7 @@ + diff --git a/examples/AspNetCore/Program.cs b/examples/AspNetCore/Program.cs index 0ee7a24c22a..a0bf9e0f3f7 100644 --- a/examples/AspNetCore/Program.cs +++ b/examples/AspNetCore/Program.cs @@ -113,13 +113,16 @@ }); // Metrics + +var metricsExporter = builder.Configuration.GetValue("UseMetricsExporter").ToLowerInvariant(); + builder.Services.AddOpenTelemetryMetrics(options => { options.ConfigureResource(configureResource) + .AddRuntimeMetrics() .AddHttpClientInstrumentation() .AddAspNetCoreInstrumentation(); - var metricsExporter = builder.Configuration.GetValue("UseMetricsExporter").ToLowerInvariant(); switch (metricsExporter) { case "prometheus": @@ -160,9 +163,7 @@ app.MapControllers(); -var metricsExporter = builder.Configuration.GetValue("UseMetricsExporter").ToLowerInvariant(); - -if (metricsExporter == "prometheus") +if (metricsExporter.Equals("prometheus", StringComparison.OrdinalIgnoreCase)) { app.UseOpenTelemetryPrometheusScrapingEndpoint(); }