Skip to content

Commit

Permalink
Minor fixes to metrics, prometheus examples (#3623)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Sep 2, 2022
1 parent c2f5e80 commit 0447871
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"appsettings",
"asax",
"cijo",
"cncf",
Expand Down Expand Up @@ -37,8 +38,8 @@
"struct",
"tbody",
"thead",
"Tracestate",
"tracestate",
"Tracestate",
"triager",
"umesan",
"unencrypted",
Expand Down
6 changes: 4 additions & 2 deletions examples/AspNetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// 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
Expand Down Expand Up @@ -90,6 +90,8 @@
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)
{
Expand All @@ -113,7 +115,7 @@
});

// Metrics

// Switch between Prometheus/OTLP/Console by setting UseMetricsExporter in appsettings.json.
var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();

builder.Services.AddOpenTelemetryMetrics(options =>
Expand Down
3 changes: 0 additions & 3 deletions examples/AspNetCore/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"Endpoint": "http://localhost:14268",
"Protocol": "UdpCompactThrift"
},
"Prometheus": {
"ScrapeResponseCacheDurationMilliseconds": 5000
},
"Zipkin": {
"ServiceName": "zipkin-test",
"Endpoint": "http://localhost:9411/api/v2/spans"
Expand Down
25 changes: 6 additions & 19 deletions src/OpenTelemetry.Exporter.Prometheus.AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,23 @@ 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
provided to change the path or for more advanced configuration a predicate
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Metrics/MetricReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract partial class MetricReader : IDisposable
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,
Expand Down

0 comments on commit 0447871

Please sign in to comment.