@ -62,8 +62,17 @@ public class MetricsWebFilter implements WebFilter {
long start = System . nanoTime ( ) ;
long start = System . nanoTime ( ) ;
ServerHttpResponse response = exchange . getResponse ( ) ;
ServerHttpResponse response = exchange . getResponse ( ) ;
return call . doOnSuccess ( ( done ) - > success ( exchange , start ) )
return call . doOnSuccess ( ( done ) - > success ( exchange , start ) )
. doOnError ( ( cause ) - > response
. doOnError ( ( cause ) - > {
. beforeCommit ( ( ) - > error ( exchange , start , cause ) ) ) ;
if ( response . isCommitted ( ) ) {
error ( exchange , start , cause ) ;
}
else {
response . beforeCommit ( ( ) - > {
error ( exchange , start , cause ) ;
return Mono . empty ( ) ;
} ) ;
}
} ) ;
}
}
private void success ( ServerWebExchange exchange , long start ) {
private void success ( ServerWebExchange exchange , long start ) {
@ -72,11 +81,10 @@ public class MetricsWebFilter implements WebFilter {
TimeUnit . NANOSECONDS ) ;
TimeUnit . NANOSECONDS ) ;
}
}
private Mono < Void > error ( ServerWebExchange exchange , long start , Throwable cause ) {
private void error ( ServerWebExchange exchange , long start , Throwable cause ) {
Iterable < Tag > tags = this . tagsProvider . httpRequestTags ( exchange , cause ) ;
Iterable < Tag > tags = this . tagsProvider . httpRequestTags ( exchange , cause ) ;
this . registry . timer ( this . metricName , tags ) . record ( System . nanoTime ( ) - start ,
this . registry . timer ( this . metricName , tags ) . record ( System . nanoTime ( ) - start ,
TimeUnit . NANOSECONDS ) ;
TimeUnit . NANOSECONDS ) ;
return Mono . empty ( ) ;
}
}
}
}