From 7da684d271151d8c510d0cc08da9f030691bb078 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 24 Jun 2022 19:24:08 -0700 Subject: [PATCH 1/2] Add runtime metrics to example aspnet core app --- build/Common.nonprod.props | 3 ++- examples/AspNetCore/Examples.AspNetCore.csproj | 1 + examples/AspNetCore/Program.cs | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props index 7e44a5db0d0..8467a8efb23 100644 --- a/build/Common.nonprod.props +++ b/build/Common.nonprod.props @@ -44,7 +44,8 @@ [12.0.2,13.0) [4.14.5,5.0) [6.1.0,7.0) - [6.2.3] + [1.0.0-beta.1,2.0) + [6.2.3] [2.4.3,3.0) [2.4.1,3.0) 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 c507e7df44e..c18981ad5a8 100644 --- a/examples/AspNetCore/Program.cs +++ b/examples/AspNetCore/Program.cs @@ -112,13 +112,16 @@ }); // Metrics + +var metricsExporter = builder.Configuration.GetValue("UseMetricsExporter").ToLowerInvariant(); + builder.Services.AddOpenTelemetryMetrics(options => { options.SetResourceBuilder(resourceBuilder) + .AddRuntimeMetrics() .AddHttpClientInstrumentation() .AddAspNetCoreInstrumentation(); - var metricsExporter = builder.Configuration.GetValue("UseMetricsExporter").ToLowerInvariant(); switch (metricsExporter) { case "prometheus": @@ -159,9 +162,7 @@ app.MapControllers(); -var metricsExporter = builder.Configuration.GetValue("UseMetricsExporter").ToLowerInvariant(); - -if (metricsExporter == "prometheus") +if (metricsExporter.Equals("prometheus", StringComparison.OrdinalIgnoreCase)) { app.UseOpenTelemetryPrometheusScrapingEndpoint(); } From dfc72b18e15c0369db1b4d09bbf441deceebe3a0 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 24 Jun 2022 19:25:57 -0700 Subject: [PATCH 2/2] clenaup space --- build/Common.nonprod.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props index 8467a8efb23..a54087528ff 100644 --- a/build/Common.nonprod.props +++ b/build/Common.nonprod.props @@ -45,7 +45,7 @@ [4.14.5,5.0) [6.1.0,7.0) [1.0.0-beta.1,2.0) - [6.2.3] + [6.2.3] [2.4.3,3.0) [2.4.1,3.0)