Add runtime metrics to example aspnet core app (#3408)
This commit is contained in:
parent
dae9f7dac2
commit
f4dddbe7da
|
@ -8,6 +8,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="$(SwashbuckleAspNetCorePkgVer)" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="$(RuntimeInstrumentationPkgVer)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue