Skip to content

Add KeyName.withNoneValue() #6125

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ default KeyValue withValue(String value) {
return KeyValue.of(this, value);
}

/**
* Creates a key value for the given key name with {@value KeyValue#NONE_VALUE}.
* @return key value
* @since 1.16.0
*/
default KeyValue withNoneValue() {
return KeyValue.of(this, KeyValue.NONE_VALUE);
}

/**
* Creates a key value for the given key name.
* @param value value for key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class DefaultApacheHttpClientObservationConvention implements ApacheHttpC

private static final KeyValue STATUS_CLIENT_ERROR = ApacheHttpClientKeyNames.STATUS.withValue("CLIENT_ERROR");

private static final KeyValue EXCEPTION_NONE = ApacheHttpClientKeyNames.EXCEPTION.withValue(KeyValue.NONE_VALUE);
private static final KeyValue EXCEPTION_NONE = ApacheHttpClientKeyNames.EXCEPTION.withNoneValue();

private static final KeyValue OUTCOME_UNKNOWN = ApacheHttpClientKeyNames.OUTCOME.withValue(Outcome.UNKNOWN.name());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.micrometer.core.instrument.binder.httpcomponents.hc5;

import io.micrometer.common.KeyValue;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
Expand Down Expand Up @@ -67,8 +66,7 @@ void shouldHaveDefaultContextName() {
void shouldContributeExceptionNoneWhenSuccess() {
HttpClientContext clientContext = HttpClientContext.create();
ApacheHttpClientContext context = new ApacheHttpClientContext(null, clientContext);
assertThat(observationConvention.getLowCardinalityKeyValues(context))
.contains(EXCEPTION.withValue(KeyValue.NONE_VALUE));
assertThat(observationConvention.getLowCardinalityKeyValues(context)).contains(EXCEPTION.withNoneValue());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.micrometer.core.instrument.binder.httpcomponents.hc5;

import io.micrometer.common.KeyValue;
import io.micrometer.common.lang.Nullable;
import io.micrometer.observation.tck.TestObservationRegistry;
import org.apache.hc.client5.http.HttpRoute;
Expand Down Expand Up @@ -165,7 +164,7 @@ void shouldInstrumentCancelledRequests() throws Exception {
assertThat(observationRegistry).hasObservationWithNameEqualTo("httpcomponents.httpclient.request")
.that()
.hasLowCardinalityKeyValue(OUTCOME.withValue("UNKNOWN"))
.hasLowCardinalityKeyValue(EXCEPTION.withValue(KeyValue.NONE_VALUE));
.hasLowCardinalityKeyValue(EXCEPTION.withNoneValue());
}

}
Expand Down