Skip to content

Add new option DisableAppendingUnitName in order to avoid appending the unit name in the metric name #6241

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Gpower2
Copy link

@Gpower2 Gpower2 commented Apr 9, 2025

Fixes #
This PR is adding a new option named "DisableAppendingUnitName" in the PrometheusAspNetCoreOptions and the PrometheusExporterOptions classes, in order to support the creation of metric names without appending the unit name.
This is very useful for migrating existing implementations that use prometheus-net to the opentelemetry-dotnet as a drop-in replacement.
I believe that Go exporter already has the same functionality but this is missing from the dotnet exporter.
I know that this adds a new option in the public API, but I believe that it will help a lot with migrating from prometheus-net for a lot of projects as already mentioned.

Changes

  • Added DisableAppendingUnitName in PrometheusAspNetCoreOptions
  • Added DisableAppendingUnitName in PrometheusExporterOptions
  • Updated OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt
  • Updated OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@Gpower2 Gpower2 requested a review from a team as a code owner April 9, 2025 09:24
Copy link

linux-foundation-easycla bot commented Apr 9, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Gpower2 / name: Arslanoglou Georgios (623d32c)

@github-actions github-actions bot added pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package perf Performance related labels Apr 9, 2025
@Gpower2 Gpower2 force-pushed the allow_unit_to_not_be_included branch from 4766821 to aa32609 Compare April 9, 2025 13:15
@Gpower2 Gpower2 force-pushed the allow_unit_to_not_be_included branch from aa32609 to 623d32c Compare April 9, 2025 14:08
@TimothyMothra
Copy link
Contributor

Default value is false, so there should be no breaking change for existing users.

Still, we're very hesitant to make changes to the public api.
What does the OpenTelemetry specification say about appending unit names?

@Gpower2
Copy link
Author

Gpower2 commented Apr 9, 2025

Default value is false, so there should be no breaking change for existing users.

Still, we're very hesitant to make changes to the public api. What does the OpenTelemetry specification say about appending unit names?

Thank you for your feedback!

I understand the hesitation, still, there is already a similar option in the public api to disable appending the Total for the counters (DisableTotalNameSuffixForCounters), so this change is in accordance to the existing public API and the benefits of having this option would be great for migrating existing apps from prometheus-net, which is a very popular and commonly used library.

Regarding the OpenTelemetry specification, correct me if I'm wrong, it doesn't specifically mention that the unit name MUST be present, but IF present, that it MUST be converted to the unit of the OTLP metric.

https://opentelemetry.io/docs/specs/otel/compatibility/prometheus_and_openmetrics/

So, based on the above reference, I believe that we don't break the specification here, since we are simply controlling if the unit name is present or not, which I don't see that is strictly required in the specification.

Again, this is my understanding of the specification, feel free to correct me or point me to another section of the specification 🙏

Last but not least, this change was driven out of need, since I am currently trying to migrate to OpenTelemetry metrics from prometheus-net, and with the current implementation of the api, all the Grafana dashboards would break.

Thank you very much checking this in any case!

Copy link
Member

@alanwest alanwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see anything in the spec that permits us to add a configuration disabling the unit suffix.

I understand the hesitation, still, there is already a similar option in the public api to disable appending the Total for the counters (DisableTotalNameSuffixForCounters)

The spec explicitly permits a configuration option for disabling the addition of the _total suffix, specifically for counters.

Exporters SHOULD provide a configuration option to disable the addition of _total suffixes.

Copy link
Contributor

@Kielek Kielek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking, per #6241 (review)

@Gpower2
Copy link
Author

Gpower2 commented Apr 11, 2025

I do not see anything in the spec that permits us to add a configuration disabling the unit suffix.

I understand the hesitation, still, there is already a similar option in the public api to disable appending the Total for the counters (DisableTotalNameSuffixForCounters)

The spec explicitly permits a configuration option for disabling the addition of the _total suffix, specifically for counters.

Exporters SHOULD provide a configuration option to disable the addition of _total suffixes.

Thank you for the reference link, I wasn't aware of this detail...

If there is a way to add this functionality in another way, without affecting the public API, would that be acceptable?

@TimothyMothra
Copy link
Contributor

Thank you for the reference link, I wasn't aware of this detail...

If there is a way to add this functionality in another way, without affecting the public API, would that be acceptable?

HI @Gpower2, I think you should open a new Feature Request Issue to discuss your problem and possible solutions.
I can't promise any immediate change, but it's a good way to gauge how many users are impacted by your issue.

I don't work with Metrics very much, but have you explored if you can use Views to rename the metrics?
https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/metrics/customizing-the-sdk#rename-an-instrument

@Gpower2
Copy link
Author

Gpower2 commented Apr 11, 2025

Thank you for the reference link, I wasn't aware of this detail...
If there is a way to add this functionality in another way, without affecting the public API, would that be acceptable?

HI @Gpower2, I think you should open a new Feature Request Issue to discuss your problem and possible solutions. I can't promise any immediate change, but it's a good way to gauge how many users are impacted by your issue.

I don't work with Metrics very much, but have you explored if you can use Views to rename the metrics? https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/metrics/customizing-the-sdk#rename-an-instrument

Thank you very much about the hint for the Views, this could be a workaround from what I gather, though I am not sure if this would affect the overall performance, definitely worth checking it out!

Regarding the Feature Request, could you give me a link or guide on where and how to open it? 🙏

@TimothyMothra
Copy link
Contributor

Thank you very much about the hint for the Views, this could be a workaround from what I gather, though I am not sure if this would affect the overall performance, definitely worth checking it out!

Regarding the Feature Request, could you give me a link or guide on where and how to open it? 🙏

Here's how you can open a Feature Request (screenshot).
However, you should test the Views first and determine if that meets your needs.
I want to set your expectations that if an existing feature can meet your needs, there's a very high bar for taking any new change.

image

Copy link
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf Performance related pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package Stale Issues and pull requests which have been flagged for closing due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants