Minor fixes to metrics, prometheus examples (#3623)
This commit is contained in:
parent
c2f5e80b0d
commit
0447871d48
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"cSpell.words": [
|
||||
"appsettings",
|
||||
"asax",
|
||||
"cijo",
|
||||
"cncf",
|
||||
|
|
@ -37,8 +38,8 @@
|
|||
"struct",
|
||||
"tbody",
|
||||
"thead",
|
||||
"Tracestate",
|
||||
"tracestate",
|
||||
"Tracestate",
|
||||
"triager",
|
||||
"umesan",
|
||||
"unencrypted",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
// OpenTelemetry
|
||||
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown";
|
||||
|
||||
// Switch between Zipkin/Jaeger/OTLP by setting UseExporter in appsettings.json.
|
||||
// Switch between Zipkin/Jaeger/OTLP/Console by setting UseTracingExporter in appsettings.json.
|
||||
var tracingExporter = builder.Configuration.GetValue<string>("UseTracingExporter").ToLowerInvariant();
|
||||
|
||||
var serviceName = tracingExporter switch
|
||||
|
|
@ -90,6 +90,8 @@ builder.Logging.ClearProviders();
|
|||
builder.Logging.AddOpenTelemetry(options =>
|
||||
{
|
||||
options.ConfigureResource(configureResource);
|
||||
|
||||
// Switch between Console/OTLP by setting UseLogExporter in appsettings.json.
|
||||
var logExporter = builder.Configuration.GetValue<string>("UseLogExporter").ToLowerInvariant();
|
||||
switch (logExporter)
|
||||
{
|
||||
|
|
@ -113,7 +115,7 @@ builder.Services.Configure<OpenTelemetryLoggerOptions>(opt =>
|
|||
});
|
||||
|
||||
// Metrics
|
||||
|
||||
// Switch between Prometheus/OTLP/Console by setting UseMetricsExporter in appsettings.json.
|
||||
var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();
|
||||
|
||||
builder.Services.AddOpenTelemetryMetrics(options =>
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@
|
|||
"Endpoint": "http://localhost:14268",
|
||||
"Protocol": "UdpCompactThrift"
|
||||
},
|
||||
"Prometheus": {
|
||||
"ScrapeResponseCacheDurationMilliseconds": 5000
|
||||
},
|
||||
"Zipkin": {
|
||||
"ServiceName": "zipkin-test",
|
||||
"Endpoint": "http://localhost:9411/api/v2/spans"
|
||||
|
|
|
|||
|
|
@ -47,18 +47,13 @@ dotnet add package --prerelease OpenTelemetry.Exporter.Prometheus.AspNetCore
|
|||
### Step 3: Configure Prometheus Scraping Endpoint
|
||||
|
||||
* Register Prometheus scraping middleware using the
|
||||
`UseOpenTelemetryPrometheusScrapingEndpoint` extension:
|
||||
`UseOpenTelemetryPrometheusScrapingEndpoint` extension method
|
||||
on `IApplicationBuilder` :
|
||||
|
||||
```csharp
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseOpenTelemetryPrometheusScrapingEndpoint();
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var app = builder.Build();
|
||||
app.UseOpenTelemetryPrometheusScrapingEndpoint();
|
||||
```
|
||||
|
||||
Overloads of the `UseOpenTelemetryPrometheusScrapingEndpoint` extension are
|
||||
|
|
@ -66,17 +61,9 @@ dotnet add package --prerelease OpenTelemetry.Exporter.Prometheus.AspNetCore
|
|||
function can be used:
|
||||
|
||||
```csharp
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseOpenTelemetryPrometheusScrapingEndpoint(
|
||||
app.UseOpenTelemetryPrometheusScrapingEndpoint(
|
||||
context => context.Request.Path == "/internal/metrics"
|
||||
&& context.Connection.LocalPort == 5067);
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@ namespace OpenTelemetry.Exporter.Prometheus
|
|||
/// </summary>
|
||||
internal static partial class PrometheusSerializer
|
||||
{
|
||||
/* Counter becomes counter
|
||||
Gauge becomes gauge
|
||||
Histogram becomes histogram
|
||||
UpDownCounter becomes gauge
|
||||
* https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#otlp-metric-points-to-prometheus
|
||||
*/
|
||||
private static readonly string[] MetricTypes = new string[]
|
||||
{
|
||||
"untyped", "counter", "gauge", "summary", "histogram", "histogram", "histogram", "histogram", "gauge",
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace OpenTelemetry.Metrics
|
|||
var type when type == typeof(ObservableCounter<>) => AggregationTemporality.Delta,
|
||||
var type when type == typeof(Histogram<>) => AggregationTemporality.Delta,
|
||||
|
||||
// Temporatlity is not defined for gauges, so this does not really affect anything.
|
||||
// Temporality is not defined for gauges, so this does not really affect anything.
|
||||
var type when type == typeof(ObservableGauge<>) => AggregationTemporality.Delta,
|
||||
|
||||
var type when type == typeof(UpDownCounter<>) => AggregationTemporality.Cumulative,
|
||||
|
|
|
|||
Loading…
Reference in New Issue