micrometer
micrometer copied to clipboard
Add KeyValue.of() variants for none values
This PR adds KeyValue.of()
variants for "none" values for convenience.
See gh-3458
:warning: 10 God Classes were detected by Lift in this project. Visit the Lift web console for more details.
We discussed this internally some time ago. My feeling is that it is a bit too context-dependent for us to provide something in the API like this. For example, when it comes to an exception
tag, the absent value makes sense as none
if we know there was no exception, but in other cases the absent value is better represented as unknown
. For that reason, I would rather we don't add these methods. Also we haven't seen a request from a user related to this yet. @jonatan-ivanov @marcingrzejszczak thoughts?
I think if somebody does something like this, there will be a check if a none
or non-none
😃 value is needed.
I think in these cases it is better to use the NONE
constant (more explicit/readable).
e.g.:
.lowCardinalityKeyvalue(KeyValue.of("something", something != null ? something : NONE));
or
String value = something != null ? something : NONE;
.lowCardinalityKeyvalue(KeyValue.of("something", value));
vs.
.lowCardinalityKeyvalue(something != null ? KeyValue.of("something", something) : KeyValue.of("something"));
or
KeyValue keyValue = something != null ? KeyValue.of("something", something) : KeyValue.of("something");
.lowCardinalityKeyvalue(keyValue);
I think that makes sense. Though if we wanted to take it a step further, we could accept null
values and convert to the none constant. I think that's a bigger change and not everyone would be happy with the behavior either. I'll close this for now and we can reopen or reconsider this kind of API if we get additional feedback.