Fix webflux sharing span across multiple threads (#5177)
This commit is contained in:
parent
a49ce988b4
commit
5cf1d122cc
|
|
@ -69,34 +69,34 @@ public class DispatcherHandlerHandleMethodInterceptor implements InstanceMethods
|
|||
span.prepareForAsync();
|
||||
ContextManager.stopSpan(span);
|
||||
|
||||
objInst.setSkyWalkingDynamicField(span);
|
||||
exchange.getAttributes().put("SKYWALING_SPAN", span);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) throws Throwable {
|
||||
ServerWebExchange exchange = (ServerWebExchange) allArguments[0];
|
||||
AbstractSpan span = (AbstractSpan) objInst.getSkyWalkingDynamicField();
|
||||
|
||||
return ((Mono) ret).doFinally(s -> {
|
||||
try {
|
||||
Object pathPattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||
if (pathPattern != null) {
|
||||
span.setOperationName(((PathPattern) pathPattern).getPatternString());
|
||||
}
|
||||
HttpStatus httpStatus = exchange.getResponse().getStatusCode();
|
||||
// fix webflux-2.0.0-2.1.0 version have bug. httpStatus is null. not support
|
||||
if (httpStatus != null) {
|
||||
Tags.STATUS_CODE.set(span, Integer.toString(httpStatus.value()));
|
||||
if (httpStatus.isError()) {
|
||||
span.errorOccurred();
|
||||
AbstractSpan span = (AbstractSpan) exchange.getAttributes().get("SKYWALING_SPAN");
|
||||
if (span != null) {
|
||||
try {
|
||||
Object pathPattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||
if (pathPattern != null) {
|
||||
span.setOperationName(((PathPattern) pathPattern).getPatternString());
|
||||
}
|
||||
HttpStatus httpStatus = exchange.getResponse().getStatusCode();
|
||||
// fix webflux-2.0.0-2.1.0 version have bug. httpStatus is null. not support
|
||||
if (httpStatus != null) {
|
||||
Tags.STATUS_CODE.set(span, Integer.toString(httpStatus.value()));
|
||||
if (httpStatus.isError()) {
|
||||
span.errorOccurred();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
span.asyncFinish();
|
||||
}
|
||||
} finally {
|
||||
span.asyncFinish();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue