Skip to content

Actuator "http.server.requests" metric has wrong "status" tag for error responses #11514

@i-kaplin

Description

@i-kaplin

Actuator reports a metric with status = 200, but controller actually responds with bad request.

MetricsWebFilter.error(ServerWebExchange exchange, long start, Throwable cause) is called with cause:

org.springframework.web.server.ServerWebInputException: Response status 400 with reason "Type mismatch."; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.util.List'; nested exception is java.lang.NumberFormatException: For input string: "invalidSkuId"

However DefaultWebFluxTagsProvider resolves status tag with 200 because of it gets status from exchange (which is null in this case) and doesn't take exception cause into consideration.

public static Tag status(ServerWebExchange exchange) {
	HttpStatus status = exchange.getResponse().getStatusCode();
	if (status == null) {
		status = HttpStatus.OK;
	}
	return Tag.of("status", status.toString());
}

Actual metric name
httpServerRequests.exception.ServerWebInputException.method.POST.status.200.uri./GoodsService/getActiveGoods.do

Expected metric name
httpServerRequests.exception.ServerWebInputException.method.POST.status.400.uri./GoodsService/getActiveGoods.do

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions