Add runtime metrics to example aspnet core app (#3408)

This commit is contained in:
Cijo Thomas 2022-06-28 06:08:46 -07:00 committed by GitHub
parent dae9f7dac2
commit f4dddbe7da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="$(SwashbuckleAspNetCorePkgVer)" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="$(RuntimeInstrumentationPkgVer)" />
</ItemGroup>
<ItemGroup>

View File

@ -113,13 +113,16 @@ builder.Services.Configure<OpenTelemetryLoggerOptions>(opt =>
});
// 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":
@ -160,9 +163,7 @@ app.UseAuthorization();
app.MapControllers();
var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();
if (metricsExporter == "prometheus")
if (metricsExporter.Equals("prometheus", StringComparison.OrdinalIgnoreCase))
{
app.UseOpenTelemetryPrometheusScrapingEndpoint();
}