|
|
|
@ -21,6 +21,8 @@ import io.micrometer.common.KeyValues; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.http.HttpStatusCode; |
|
|
|
import org.springframework.http.HttpStatusCode; |
|
|
|
|
|
|
|
import org.springframework.http.observation.reactive.ServerHttpObservationDocumentation.HighCardinalityKeyNames; |
|
|
|
|
|
|
|
import org.springframework.http.observation.reactive.ServerHttpObservationDocumentation.LowCardinalityKeyNames; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.web.util.pattern.PathPattern; |
|
|
|
import org.springframework.web.util.pattern.PathPattern; |
|
|
|
|
|
|
|
|
|
|
|
@ -34,28 +36,30 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO |
|
|
|
|
|
|
|
|
|
|
|
private static final String DEFAULT_NAME = "http.server.requests"; |
|
|
|
private static final String DEFAULT_NAME = "http.server.requests"; |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue METHOD_UNKNOWN = KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.METHOD, "UNKNOWN"); |
|
|
|
private static final KeyValue METHOD_UNKNOWN = KeyValue.of(LowCardinalityKeyNames.METHOD, "UNKNOWN"); |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue STATUS_UNKNOWN = KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.STATUS, "UNKNOWN"); |
|
|
|
private static final KeyValue STATUS_UNKNOWN = KeyValue.of(LowCardinalityKeyNames.STATUS, "UNKNOWN"); |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue HTTP_OUTCOME_SUCCESS = KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.OUTCOME, "SUCCESS"); |
|
|
|
private static final KeyValue HTTP_OUTCOME_SUCCESS = KeyValue.of(LowCardinalityKeyNames.OUTCOME, "SUCCESS"); |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue HTTP_OUTCOME_UNKNOWN = KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.OUTCOME, "UNKNOWN"); |
|
|
|
private static final KeyValue HTTP_OUTCOME_UNKNOWN = KeyValue.of(LowCardinalityKeyNames.OUTCOME, "UNKNOWN"); |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue URI_UNKNOWN = KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.URI, "UNKNOWN"); |
|
|
|
private static final KeyValue URI_UNKNOWN = KeyValue.of(LowCardinalityKeyNames.URI, "UNKNOWN"); |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue URI_ROOT = KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.URI, "root"); |
|
|
|
private static final KeyValue URI_ROOT = KeyValue.of(LowCardinalityKeyNames.URI, "root"); |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue URI_NOT_FOUND = KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.URI, "NOT_FOUND"); |
|
|
|
private static final KeyValue URI_NOT_FOUND = KeyValue.of(LowCardinalityKeyNames.URI, "NOT_FOUND"); |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue URI_REDIRECTION = KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.URI, "REDIRECTION"); |
|
|
|
private static final KeyValue URI_REDIRECTION = KeyValue.of(LowCardinalityKeyNames.URI, "REDIRECTION"); |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue EXCEPTION_NONE = KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.EXCEPTION, KeyValue.NONE_VALUE); |
|
|
|
private static final KeyValue EXCEPTION_NONE = KeyValue.of(LowCardinalityKeyNames.EXCEPTION, KeyValue.NONE_VALUE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue HTTP_URL_UNKNOWN = KeyValue.of(HighCardinalityKeyNames.HTTP_URL, "UNKNOWN"); |
|
|
|
|
|
|
|
|
|
|
|
private static final KeyValue HTTP_URL_UNKNOWN = KeyValue.of(ServerHttpObservationDocumentation.HighCardinalityKeyNames.HTTP_URL, "UNKNOWN"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String name; |
|
|
|
private final String name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a convention with the default name {@code "http.server.requests"}. |
|
|
|
* Create a convention with the default name {@code "http.server.requests"}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -65,13 +69,13 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a convention with a custom name. |
|
|
|
* Create a convention with a custom name. |
|
|
|
* |
|
|
|
|
|
|
|
* @param name the observation name |
|
|
|
* @param name the observation name |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public DefaultServerRequestObservationConvention(String name) { |
|
|
|
public DefaultServerRequestObservationConvention(String name) { |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getName() { |
|
|
|
public String getName() { |
|
|
|
return this.name; |
|
|
|
return this.name; |
|
|
|
@ -79,11 +83,11 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getContextualName(ServerRequestObservationContext context) { |
|
|
|
public String getContextualName(ServerRequestObservationContext context) { |
|
|
|
|
|
|
|
String httpMethod = context.getCarrier().getMethod().name().toLowerCase(); |
|
|
|
if (context.getPathPattern() != null) { |
|
|
|
if (context.getPathPattern() != null) { |
|
|
|
return String.format("http %s %s", context.getCarrier().getMethod().name().toLowerCase(), |
|
|
|
return "http %s %s".formatted(httpMethod, context.getPathPattern()); |
|
|
|
context.getPathPattern().toString()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return "http " + context.getCarrier().getMethod().name().toLowerCase(); |
|
|
|
return "http " + httpMethod; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -97,7 +101,9 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected KeyValue method(ServerRequestObservationContext context) { |
|
|
|
protected KeyValue method(ServerRequestObservationContext context) { |
|
|
|
return (context.getCarrier() != null) ? KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.METHOD, context.getCarrier().getMethod().name()) : METHOD_UNKNOWN; |
|
|
|
return (context.getCarrier() != null) ? |
|
|
|
|
|
|
|
KeyValue.of(LowCardinalityKeyNames.METHOD, context.getCarrier().getMethod().name()) : |
|
|
|
|
|
|
|
METHOD_UNKNOWN; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected KeyValue status(ServerRequestObservationContext context) { |
|
|
|
protected KeyValue status(ServerRequestObservationContext context) { |
|
|
|
@ -105,7 +111,8 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO |
|
|
|
return STATUS_UNKNOWN; |
|
|
|
return STATUS_UNKNOWN; |
|
|
|
} |
|
|
|
} |
|
|
|
return (context.getResponse() != null && context.getResponse().getStatusCode() != null) ? |
|
|
|
return (context.getResponse() != null && context.getResponse().getStatusCode() != null) ? |
|
|
|
KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.STATUS, Integer.toString(context.getResponse().getStatusCode().value())) : STATUS_UNKNOWN; |
|
|
|
KeyValue.of(LowCardinalityKeyNames.STATUS, Integer.toString(context.getResponse().getStatusCode().value())) : |
|
|
|
|
|
|
|
STATUS_UNKNOWN; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected KeyValue uri(ServerRequestObservationContext context) { |
|
|
|
protected KeyValue uri(ServerRequestObservationContext context) { |
|
|
|
@ -115,7 +122,7 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO |
|
|
|
if (pattern.toString().isEmpty()) { |
|
|
|
if (pattern.toString().isEmpty()) { |
|
|
|
return URI_ROOT; |
|
|
|
return URI_ROOT; |
|
|
|
} |
|
|
|
} |
|
|
|
return KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.URI, pattern.toString()); |
|
|
|
return KeyValue.of(LowCardinalityKeyNames.URI, pattern.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (context.getResponse() != null && context.getResponse().getStatusCode() != null) { |
|
|
|
if (context.getResponse() != null && context.getResponse().getStatusCode() != null) { |
|
|
|
HttpStatus status = HttpStatus.resolve(context.getResponse().getStatusCode().value()); |
|
|
|
HttpStatus status = HttpStatus.resolve(context.getResponse().getStatusCode().value()); |
|
|
|
@ -136,8 +143,8 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO |
|
|
|
Throwable error = context.getError(); |
|
|
|
Throwable error = context.getError(); |
|
|
|
if (error != null) { |
|
|
|
if (error != null) { |
|
|
|
String simpleName = error.getClass().getSimpleName(); |
|
|
|
String simpleName = error.getClass().getSimpleName(); |
|
|
|
return KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.EXCEPTION, |
|
|
|
return KeyValue.of(LowCardinalityKeyNames.EXCEPTION, StringUtils.hasText(simpleName) ? |
|
|
|
StringUtils.hasText(simpleName) ? simpleName : error.getClass().getName()); |
|
|
|
simpleName : error.getClass().getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
return EXCEPTION_NONE; |
|
|
|
return EXCEPTION_NONE; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -154,11 +161,12 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO |
|
|
|
|
|
|
|
|
|
|
|
protected KeyValue httpUrl(ServerRequestObservationContext context) { |
|
|
|
protected KeyValue httpUrl(ServerRequestObservationContext context) { |
|
|
|
if (context.getCarrier() != null) { |
|
|
|
if (context.getCarrier() != null) { |
|
|
|
return KeyValue.of(ServerHttpObservationDocumentation.HighCardinalityKeyNames.HTTP_URL, context.getCarrier().getPath().toString()); |
|
|
|
return KeyValue.of(HighCardinalityKeyNames.HTTP_URL, context.getCarrier().getPath().toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
return HTTP_URL_UNKNOWN; |
|
|
|
return HTTP_URL_UNKNOWN; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class HttpOutcome { |
|
|
|
static class HttpOutcome { |
|
|
|
|
|
|
|
|
|
|
|
static KeyValue forStatus(HttpStatusCode statusCode) { |
|
|
|
static KeyValue forStatus(HttpStatusCode statusCode) { |
|
|
|
@ -166,7 +174,7 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO |
|
|
|
return HTTP_OUTCOME_SUCCESS; |
|
|
|
return HTTP_OUTCOME_SUCCESS; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (statusCode instanceof HttpStatus status) { |
|
|
|
else if (statusCode instanceof HttpStatus status) { |
|
|
|
return KeyValue.of(ServerHttpObservationDocumentation.LowCardinalityKeyNames.OUTCOME, status.series().name()); |
|
|
|
return KeyValue.of(LowCardinalityKeyNames.OUTCOME, status.series().name()); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
return HTTP_OUTCOME_UNKNOWN; |
|
|
|
return HTTP_OUTCOME_UNKNOWN; |
|
|
|
|