Add __repr__ method to metric objects, make them debug friendly.#481
Merged
brian-brazil merged 2 commits intoprometheus:masterfrom Oct 30, 2019
Merged
Add __repr__ method to metric objects, make them debug friendly.#481brian-brazil merged 2 commits intoprometheus:masterfrom
brian-brazil merged 2 commits intoprometheus:masterfrom
Conversation
Signed-off-by: Asher Foa <asher@asherfoa.com>
prometheus_client/metrics.py
Outdated
|
|
||
| def __repr__(self): | ||
| metric_type = type(self) | ||
| return "{0}.{1}:{2}".format(metric_type.__module__, metric_type.__name__, self._name) |
Contributor
There was a problem hiding this comment.
A repr() should in principle allow instantiation of the object. This would be a __str__. Also _type covers you more here.
Contributor
Author
There was a problem hiding this comment.
As far as using the _type, I added an __str__ implementation that uses it.
I think having the full type path is useful in repr output which what is used in debuggers.
I updated the __repr__ implementation to use parenthesis instead of a column to be more compatible with the ability to pass eval
However, I feel that making it a 100% compatible with that (i.e. an eval(repr(metric)) that produces an identical object) will result in a string that will be too noisy and thus less useful when debugging.
Signed-off-by: Asher Foa <asher@asherfoa.com>
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
before:

after:
