Skip to content

Commit

Permalink
Add runtime metrics to example aspnet core app (#3408)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Jun 28, 2022
1 parent dae9f7d commit f4dddbe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/AspNetCore/Examples.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="$(SwashbuckleAspNetCorePkgVer)" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="$(RuntimeInstrumentationPkgVer)" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions examples/AspNetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,16 @@
});

// Metrics

var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();

builder.Services.AddOpenTelemetryMetrics(options =>
{
options.ConfigureResource(configureResource)
.AddRuntimeMetrics()
.AddHttpClientInstrumentation()
.AddAspNetCoreInstrumentation();

var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();
switch (metricsExporter)
{
case "prometheus":
Expand Down Expand Up @@ -160,9 +163,7 @@

app.MapControllers();

var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();

if (metricsExporter == "prometheus")
if (metricsExporter.Equals("prometheus", StringComparison.OrdinalIgnoreCase))
{
app.UseOpenTelemetryPrometheusScrapingEndpoint();
}
Expand Down

0 comments on commit f4dddbe

Please sign in to comment.