Add runtime metrics to example aspnet core app (#3408)
This commit is contained in:
parent
dae9f7dac2
commit
f4dddbe7da
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="$(SwashbuckleAspNetCorePkgVer)" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="$(SwashbuckleAspNetCorePkgVer)" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="$(RuntimeInstrumentationPkgVer)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -113,13 +113,16 @@ builder.Services.Configure<OpenTelemetryLoggerOptions>(opt =>
|
||||||
});
|
});
|
||||||
|
|
||||||
// Metrics
|
// Metrics
|
||||||
|
|
||||||
|
var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();
|
||||||
|
|
||||||
builder.Services.AddOpenTelemetryMetrics(options =>
|
builder.Services.AddOpenTelemetryMetrics(options =>
|
||||||
{
|
{
|
||||||
options.ConfigureResource(configureResource)
|
options.ConfigureResource(configureResource)
|
||||||
|
.AddRuntimeMetrics()
|
||||||
.AddHttpClientInstrumentation()
|
.AddHttpClientInstrumentation()
|
||||||
.AddAspNetCoreInstrumentation();
|
.AddAspNetCoreInstrumentation();
|
||||||
|
|
||||||
var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();
|
|
||||||
switch (metricsExporter)
|
switch (metricsExporter)
|
||||||
{
|
{
|
||||||
case "prometheus":
|
case "prometheus":
|
||||||
|
|
@ -160,9 +163,7 @@ app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();
|
if (metricsExporter.Equals("prometheus", StringComparison.OrdinalIgnoreCase))
|
||||||
|
|
||||||
if (metricsExporter == "prometheus")
|
|
||||||
{
|
{
|
||||||
app.UseOpenTelemetryPrometheusScrapingEndpoint();
|
app.UseOpenTelemetryPrometheusScrapingEndpoint();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue