Skip to content

Commit

Permalink
fix spring-webflux cast to PathPattern throws ClassCastException (ope…
Browse files Browse the repository at this point in the history
…n-telemetry#6872)

when
ServerWebExchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
"path string type").
opentelemetry javaagent will throw exception.

[企业微信截图_76344afd-4541-482c-a90f-0606ad720351](https://user-images.githubusercontent.com/15957476/195615160-45559fb5-5e0c-4c25-8678-7d8aa603f346.png)
  • Loading branch information
wang007 authored and LironKS committed Dec 4, 2022
1 parent 272a25d commit ebde33a
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ public static Instrumenter<Object, Void> instrumenter() {

public static HttpRouteGetter<ServerWebExchange> httpRouteGetter() {
return (context, exchange) -> {
PathPattern bestPattern =
exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
return bestPattern == null ? null : bestPattern.getPatternString();
Object bestPatternObj = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (bestPatternObj == null) {
return null;
}
if (bestPatternObj instanceof PathPattern) {
return ((PathPattern) bestPatternObj).getPatternString();
}
return bestPatternObj.toString();
};
}

Expand Down

0 comments on commit ebde33a

Please sign in to comment.