Skip to content

Conversation

@duricanikolic
Copy link

@duricanikolic duricanikolic commented Oct 31, 2025

Adds a public Err() method to Desc type to allow users to check if an error occurred during descriptor construction. Previously, the error field was private and inaccessible.

Our use case is as follows:

  • We create a Desc.
  • We define and register a custom collector.
  • In the collector’s Collect() method, we dynamically create a Metric using NewConstMetric() to report the current value.

However, if the Desc was constructed with an error (for example, due to an invalid label name), that error remains hidden until the collector’s Collect() method is invoked for the first time.

It would be much more practical if the Prometheus API exposed a method such as Desc.Err(), which would return any error that occurred during the creation of the Desc. That's the motivation for the present PR.

Signed-off-by: Yuri Nikolic durica.nikolic@grafana.com

Adds a public Err() method to Desc type to allow users to check if
an error occurred during descriptor construction. Previously, the error
field was private and inaccessible.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Yuri Nikolic <durica.nikolic@grafana.com>
Copy link
Member

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants