diff --git a/micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/web/WebMetricsHelper.java b/micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/web/WebMetricsHelper.java index c9b576e92..d7a005a54 100644 --- a/micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/web/WebMetricsHelper.java +++ b/micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/web/WebMetricsHelper.java @@ -250,8 +250,9 @@ static String sanitizePath(@Nullable String path) { * @param httpResponse the HTTP response */ public void onResponse(HttpResponse httpResponse) { - Throwable throwable = httpResponse.getAttribute(HttpAttributes.EXCEPTION, Throwable.class).orElse(null); - if (throwable != null) { + // Avoid using the conversion service for exceptions + Object exception = httpResponse.getAttribute(HttpAttributes.EXCEPTION).orElse(null); + if (exception instanceof Throwable throwable) { RouteMatch routeMatch = httpResponse.getAttribute(HttpAttributes.ROUTE_MATCH, RouteMatch.class).orElse(null); if (routeMatch != null && routeMatch.getRouteInfo() instanceof ErrorRouteInfo) { // Avoid publishing an error on error route