-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix WebFlux instrumentation after SPR-17395 #14876
Comments
Here is a workaround in the meantime - developers can override the default package com.example.demo;
import java.util.Arrays;
import io.micrometer.core.instrument.Tag;
import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTags;
import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.pattern.PathPattern;
@Configuration
public class WebFluxMetrixConfig {
@Bean
public WebFluxTagsProvider customTagsProvider() {
return new WebFluxTagsProvider() {
private final Tag URI_NOT_FOUND = Tag.of("uri", "NOT_FOUND");
private final Tag URI_REDIRECTION = Tag.of("uri", "REDIRECTION");
private final Tag URI_ROOT = Tag.of("uri", "root");
@Override
public Iterable<Tag> httpRequestTags(ServerWebExchange exchange, Throwable exception) {
return Arrays.asList(WebFluxTags.method(exchange), uriTag(exchange),
WebFluxTags.exception(exception), WebFluxTags.status(exchange),
WebFluxTags.outcome(exchange));
}
Tag uriTag(ServerWebExchange exchange) {
String matchingPattern = exchange
.getAttribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
if (matchingPattern != null) {
return Tag.of("uri", matchingPattern);
}
PathPattern pathPattern = exchange
.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (pathPattern != null) {
return Tag.of("uri", pathPattern.getPatternString());
}
HttpStatus status = exchange.getResponse().getStatusCode();
if (status != null) {
if (status.is3xxRedirection()) {
return URI_REDIRECTION;
}
if (status == HttpStatus.NOT_FOUND) {
return URI_NOT_FOUND;
}
}
String path = exchange.getRequest().getPath().value();
if (path.isEmpty()) {
return URI_ROOT;
}
return Tag.of("uri", path);
}
};
}
} Note that this implementation should not be kept around after upgrading to the next Spring Boot version, as underlying Spring Framework changes will make it unfit. |
It works for me, thanks! |
SPR-17395 ensures that WebFlux.fn is adding a request attribute of type `PathPattern` on the `HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE`. A specific tag provider for WebFlux.fn is no longer necessary. See gh-14876
SPR-17395 added integration tests for this case. I've just updated the instrumentation since we don't need a specific case for WebFlux.fn now - everything is configured through |
After update to Spring Boot 2.1.0.RC1,
ClassCastException
occurred as followsWhile this is an issue in Spring Framework, Spring Boot should have an integration test to detect this detect that.
The text was updated successfully, but these errors were encountered: