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
Add Tags.of
method taking array of Pair
#4960
Comments
With reference to
I think we've had this request before, but I'm not sure I think it's something we should do. I don't think it should be Micrometer's responsibility to convert arbitrary values to strings. Micrometer should treat tag values as opaque so what users give Micrometer is what ends up in the metrics backend (other than limitations imposed by backends and handled by |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
@shakuzen This is absolutely achievable via an extension function: fun MeterRegistry.counter(id: String, vararg tags: Pair<String, String>): Counter {
return this.counter(id, tags.map { Tag.of(it.first, it.second) })
} I also agree that Micrometer should only be accepting strings for tag and not convert an into to a string. If the user want a convenient conversion then they could call I would love for Kotlin extension function to be available to import, that way they are only visible to those users and not noise for the rest of the users. Is there currently a Kotlin part of the build that would be a good place to put such extension functions? |
Yes,
It makes sense to me too to only expose them for Kotlin users. It's hard to imagine why non-Kotlin users would need to use |
I guess My questions are:
|
That is perfect and using the same approach: add extension methods there that Kotlin users can import and Java users won't see. As long as the extension methods are only leveraging core classes like The Kotlin dependency should be an |
Please describe the feature request.
I would like to be able to provide metric tags as array of
Pair
objectsRationale
Currently I have two ways to pass tags:
First method may lead to runtime errors if someone forgets to provide key or value resulting in uneven number of tag arguments.
Second method is too verbose.
I would like to be able to write in Kotlin:
Note:
to
operator in Kotlin creates aPair
object so this is equivalent to:Nice to have: additional methods in
MeterRegistry
class allowing to avoid dealing withTags
class - probably a breaking change?Additionally it would be nice if Micrometer allowed passing values of any type and converting them to
String
automatically, e.g.:The text was updated successfully, but these errors were encountered: