dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.93k stars 480 forks source link

Aspire Dashboard Metrics: Exponential Histograms do not display #4381

Open JackRhodes opened 5 months ago

JackRhodes commented 5 months ago

The Aspire dashboard does not show any data points when using Exponential Histograms. It will show the metric within the dashboard, but nothing will be plotted on the graph.

Failing code:

// See https://aka.ms/new-console-template for more information

using System.Diagnostics.Metrics;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;

using var meter = new Meter("TestMeter", "1.0.0");

var providerBuilder = Sdk.CreateMeterProviderBuilder()
    .ConfigureResource(r => r.AddService("testservice"))
    .AddMeter(meter.Name); // All instruments from this meter are enabled.

// Use Exponential Histogram
providerBuilder.AddView(
    instrument => instrument.GetType().GetGenericTypeDefinition() == typeof(Histogram<>)
        ? new Base2ExponentialBucketHistogramConfiguration()
        : null
);

providerBuilder.AddOtlpExporter();

var provider = providerBuilder.Build();

while (true)
{
    await Task.Delay(TimeSpan.FromSeconds(1));
    meter.CreateHistogram<long>("foo").Record(1);
}

image

Working code (using fixed bucket histogram)

// See https://aka.ms/new-console-template for more information

using System.Diagnostics.Metrics;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;

using var meter = new Meter("TestMeter", "1.0.0");

var providerBuilder = Sdk.CreateMeterProviderBuilder()
    .ConfigureResource(r => r.AddService("testservice"))
    .AddMeter(meter.Name); // All instruments from this meter are enabled.

providerBuilder.AddOtlpExporter();

var provider = providerBuilder.Build();

while (true)
{
    await Task.Delay(TimeSpan.FromSeconds(1));
    meter.CreateHistogram<long>("foo").Record(1);
}

image

adamint commented 5 months ago

@JamesNK

JamesNK commented 5 months ago

I think the data and the logic to display them is different. I didn't test with them so not surprised it's currently not working.