Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prometheus metric names incorrectly append unit #4742

Closed
JamesNK opened this issue Aug 4, 2023 · 2 comments · Fixed by #4753
Closed

Prometheus metric names incorrectly append unit #4742

JamesNK opened this issue Aug 4, 2023 · 2 comments · Fixed by #4753
Labels
bug Something isn't working pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package

Comments

@JamesNK
Copy link
Contributor

JamesNK commented Aug 4, 2023

Bug Report

List of all OpenTelemetry NuGet
packages
and version that you are
using (e.g. OpenTelemetry 1.0.2):

  • OpenTelemetry.Exporter.Prometheus.AspNetCore 1.6.0-alpha.1
  • OpenTelemetry.Extensions.Hosting 1.6.0-alpha.1

Runtime version (e.g. net462, net48, netcoreapp3.1, net6.0 etc. You can
find this information from the *.csproj file):

  • net7.0

Symptom

The .NET prometheus exporter doesn't correctly follow the specification for outputting units:

https://github.com/open-telemetry/opentelemetry-specification/blob/065b25024549120800da7cda6ccd9717658ff0df/specification/compatibility/prometheus_and_openmetrics.md?plain=1#L235-L240

For example, a unit in brackets is included in the output. Brackets should be removed.

.NET code:

image

Output:

image

This counter shouldn't have a unit because {TestUnitWithBrackets} is surrounded by brackets.

What is the expected behavior?

No unit on the counter.

What is the actual behavior?

The counter has a unit of TestUnitWithBrackets

Reproduce

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

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetry()
    .WithMetrics(builder =>
    {
        builder.AddPrometheusExporter();

        builder.AddMeter("HelloWorld");
    });

var app = builder.Build();

var meter = new Meter("HelloWorld");
var counter = meter.CreateCounter<int>("Test.Counter", unit: "{TestUnitWithBrackets}");

app.MapGet("/", () =>
{
    counter.Add(1);
    return "Hello World!";
});
app.MapPrometheusScrapingEndpoint();

app.Run();

We will close this issue if:

  • The repro project you share with us is complex. We can't investigate custom
    projects, so don't point us to such, please.
  • If we can not reproduce the behavior you're reporting.

Additional Context

Add any other context about the problem here.

@JamesNK JamesNK added the bug Something isn't working label Aug 4, 2023
@JamesNK
Copy link
Contributor Author

JamesNK commented Aug 4, 2023

There are other things the .NET exporter isn't doing. It's supposed to map to Prometheus units. For example, s becomes seconds.

For example, this is what go has to implement this behavior: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/9a9d4778bbbf242dba233db28e2fbcfda3416959/pkg/translator/prometheus/normalize_name.go#L30

Here is Java implementing this feature: open-telemetry/opentelemetry-java#5400

@JamesNK
Copy link
Contributor Author

JamesNK commented Aug 4, 2023

I think it's important that this is fixed sooner rather than later. When it is fixed the metric names in Prometheus output will change, and people will have to react to the new names. For example, people who have written dashboards or alerts on the names will be broken and need to update Prometheus/Grafana/etc.

The sooner it is fixed, the fewer people will be impacted.

@cijothomas cijothomas added the pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package label Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants