Make client.name low cardinality keyvalue for client observations
Prior to this commit, the `"client.name"` key value for the `"http.client.requests"` client HTTP observations would be considered as high cardinality, as the URI host is technically unbounded. In practice, the number of hosts used by a client in a given application can be considered as low cardinality. This commit moves this keyvalue to low cardinality so that it's present for both metrics and traces. Closes gh-29839
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,7 +50,7 @@ public enum ClientHttpObservationDocumentation implements ObservationDocumentati
|
||||
|
||||
@Override
|
||||
public KeyName[] getHighCardinalityKeyNames() {
|
||||
return HighCardinalityKeyNames.values();
|
||||
return new KeyName[] {HighCardinalityKeyNames.HTTP_URL};
|
||||
}
|
||||
|
||||
};
|
||||
@@ -89,6 +89,17 @@ public enum ClientHttpObservationDocumentation implements ObservationDocumentati
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Client name derived from the request URI host.
|
||||
*/
|
||||
CLIENT_NAME {
|
||||
@Override
|
||||
public String asString() {
|
||||
return "client.name";
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Name of the exception thrown during the exchange, or {@value KeyValue#NONE_VALUE} if no exception happened.
|
||||
*/
|
||||
@@ -126,7 +137,10 @@ public enum ClientHttpObservationDocumentation implements ObservationDocumentati
|
||||
|
||||
/**
|
||||
* Client name derived from the request URI host.
|
||||
* @deprecated in favor of {@link LowCardinalityKeyNames#CLIENT_NAME}.
|
||||
* This will be available both as a low and high cardinality key value.
|
||||
*/
|
||||
@Deprecated(since = "6.0.5", forRemoval = true)
|
||||
CLIENT_NAME {
|
||||
@Override
|
||||
public String asString() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,12 +51,12 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO
|
||||
|
||||
private static final KeyValue HTTP_OUTCOME_UNKNOWN = KeyValue.of(LowCardinalityKeyNames.OUTCOME, "UNKNOWN");
|
||||
|
||||
private static final KeyValue CLIENT_NAME_NONE = KeyValue.of(LowCardinalityKeyNames.CLIENT_NAME, KeyValue.NONE_VALUE);
|
||||
|
||||
private static final KeyValue EXCEPTION_NONE = KeyValue.of(LowCardinalityKeyNames.EXCEPTION, KeyValue.NONE_VALUE);
|
||||
|
||||
private static final KeyValue HTTP_URL_NONE = KeyValue.of(HighCardinalityKeyNames.HTTP_URL, KeyValue.NONE_VALUE);
|
||||
|
||||
private static final KeyValue CLIENT_NAME_NONE = KeyValue.of(HighCardinalityKeyNames.CLIENT_NAME, KeyValue.NONE_VALUE);
|
||||
|
||||
|
||||
private final String name;
|
||||
|
||||
@@ -87,7 +87,7 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO
|
||||
|
||||
@Override
|
||||
public KeyValues getLowCardinalityKeyValues(ClientRequestObservationContext context) {
|
||||
return KeyValues.of(uri(context), method(context), status(context), exception(context), outcome(context));
|
||||
return KeyValues.of(uri(context), method(context), status(context), clientName(context), exception(context), outcome(context));
|
||||
}
|
||||
|
||||
protected KeyValue uri(ClientRequestObservationContext context) {
|
||||
@@ -119,6 +119,13 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO
|
||||
}
|
||||
}
|
||||
|
||||
protected KeyValue clientName(ClientRequestObservationContext context) {
|
||||
if (context.getCarrier() != null && context.getCarrier().getURI().getHost() != null) {
|
||||
return KeyValue.of(LowCardinalityKeyNames.CLIENT_NAME, context.getCarrier().getURI().getHost());
|
||||
}
|
||||
return CLIENT_NAME_NONE;
|
||||
}
|
||||
|
||||
protected KeyValue exception(ClientRequestObservationContext context) {
|
||||
Throwable error = context.getError();
|
||||
if (error != null) {
|
||||
@@ -129,7 +136,7 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO
|
||||
return EXCEPTION_NONE;
|
||||
}
|
||||
|
||||
protected static KeyValue outcome(ClientRequestObservationContext context) {
|
||||
protected KeyValue outcome(ClientRequestObservationContext context) {
|
||||
if (context.getResponse() != null) {
|
||||
try {
|
||||
return HttpOutcome.forStatus(context.getResponse().getStatusCode());
|
||||
@@ -143,7 +150,7 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO
|
||||
|
||||
@Override
|
||||
public KeyValues getHighCardinalityKeyValues(ClientRequestObservationContext context) {
|
||||
return KeyValues.of(requestUri(context), clientName(context));
|
||||
return KeyValues.of(requestUri(context));
|
||||
}
|
||||
|
||||
protected KeyValue requestUri(ClientRequestObservationContext context) {
|
||||
@@ -153,12 +160,6 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO
|
||||
return HTTP_URL_NONE;
|
||||
}
|
||||
|
||||
protected KeyValue clientName(ClientRequestObservationContext context) {
|
||||
if (context.getCarrier() != null && context.getCarrier().getURI().getHost() != null) {
|
||||
return KeyValue.of(HighCardinalityKeyNames.CLIENT_NAME, context.getCarrier().getURI().getHost());
|
||||
}
|
||||
return CLIENT_NAME_NONE;
|
||||
}
|
||||
|
||||
static class HttpOutcome {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user