micrometer-metrics/micrometer

Add `Tags.of` method taking array of `Pair`

Ouverte

#4 960 ouverte le 11 avr. 2024

 (6 commentaires) (0 réaction) (0 personne assignée)Java (1 133 forks)batch import
enhancementhelp wantedkotlinmodule: micrometer-core

Métriques du dépôt

Stars
 (4 882 étoiles)
Métriques de merge PR
 (Merge moyen 1j 21h) (100 PRs mergées en 30 j)

Description

Please describe the feature request.

I would like to be able to provide metric tags as array of Pair objects

Rationale

Currently I have two ways to pass tags:

meterRegistry.counter(path, "foo", foo, "bar", bar).increment()                           // 1
meterRegistry.counter(path, Tags.of(Tag.of("foo", foo), Tag.of("bar", bar))).increment()  // 2

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:

meterRegistry.counter(path, Tags.of("foo" to foo, "bar" to bar)).increment()

Note: to operator in Kotlin creates a Pair object so this is equivalent to:

meterRegistry.counter(path, Tags.of(Pair("foo", foo), Pair("bar", bar))).increment()

Nice to have: additional methods in MeterRegistry class allowing to avoid dealing with Tags class - probably a breaking change?

meterRegistry.counter(path, "foo" to foo, "bar" to bar).increment()

Additionally it would be nice if Micrometer allowed passing values of any type and converting them to String automatically, e.g.:

meterRegistry.counter(path, Tags.of("foo" to 10)).increment()

Guide contributeur