未验证 提交 58a37010 编写于 作者: Linjingchun97's avatar Linjingchun97 提交者: GitHub

Fix issue that webfluxwebclient plugin async finish repeatedly in multi thread (#7229)

上级 04bb6673
...@@ -26,6 +26,7 @@ Release Notes. ...@@ -26,6 +26,7 @@ Release Notes.
* Support parameter collection for SqlServer. * Support parameter collection for SqlServer.
* Add `ShardingSphere-5.0.0-beta` plugin. * Add `ShardingSphere-5.0.0-beta` plugin.
* Fix some method exception error. * Fix some method exception error.
* Fix async finish repeatedly in `spring-webflux-5.x-webclient` plugin.
#### OAP-Backend #### OAP-Backend
......
...@@ -24,8 +24,8 @@ import org.apache.skywalking.apm.agent.core.context.tag.Tags; ...@@ -24,8 +24,8 @@ import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.InstanceMethodsAroundInterceptorV2;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.MethodInvocationContext;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientRequest;
...@@ -36,10 +36,10 @@ import java.lang.reflect.Method; ...@@ -36,10 +36,10 @@ import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
public class WebFluxWebClientInterceptor implements InstanceMethodsAroundInterceptor { public class WebFluxWebClientInterceptor implements InstanceMethodsAroundInterceptorV2 {
@Override @Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInvocationContext context) throws Throwable {
if (allArguments[0] == null) { if (allArguments[0] == null) {
//illegal args,can't trace ignore //illegal args,can't trace ignore
return; return;
...@@ -68,17 +68,17 @@ public class WebFluxWebClientInterceptor implements InstanceMethodsAroundInterce ...@@ -68,17 +68,17 @@ public class WebFluxWebClientInterceptor implements InstanceMethodsAroundInterce
span.prepareForAsync(); span.prepareForAsync();
ContextManager.stopSpan(); ContextManager.stopSpan();
objInst.setSkyWalkingDynamicField(span); context.setContext(span);
} }
@Override @Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret, MethodInvocationContext context) throws Throwable {
// fix the problem that allArgument[0] may be null // fix the problem that allArgument[0] may be null
if (allArguments[0] == null) { if (allArguments[0] == null) {
return ret; return ret;
} }
Mono<ClientResponse> ret1 = (Mono<ClientResponse>) ret; Mono<ClientResponse> ret1 = (Mono<ClientResponse>) ret;
AbstractSpan span = (AbstractSpan) objInst.getSkyWalkingDynamicField(); AbstractSpan span = (AbstractSpan) context.getContext();
return ret1.doAfterSuccessOrError(new BiConsumer<ClientResponse, Throwable>() { return ret1.doAfterSuccessOrError(new BiConsumer<ClientResponse, Throwable>() {
@Override @Override
public void accept(ClientResponse clientResponse, Throwable throwable) { public void accept(ClientResponse clientResponse, Throwable throwable) {
...@@ -98,7 +98,7 @@ public class WebFluxWebClientInterceptor implements InstanceMethodsAroundInterce ...@@ -98,7 +98,7 @@ public class WebFluxWebClientInterceptor implements InstanceMethodsAroundInterce
} }
@Override @Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t, MethodInvocationContext context) {
AbstractSpan activeSpan = ContextManager.activeSpan(); AbstractSpan activeSpan = ContextManager.activeSpan();
activeSpan.errorOccurred(); activeSpan.errorOccurred();
activeSpan.log(t); activeSpan.log(t);
......
...@@ -21,15 +21,15 @@ package org.apache.skywalking.apm.plugin.spring.webflux.v5.webclient.define; ...@@ -21,15 +21,15 @@ package org.apache.skywalking.apm.plugin.spring.webflux.v5.webclient.define;
import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.v2.InstanceMethodsInterceptV2Point;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.ClassInstanceMethodsEnhancePluginDefineV2;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.named;
public class WebFluxWebClientInstrumentation extends ClassEnhancePluginDefine { public class WebFluxWebClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefineV2 {
private static final String ENHANCE_CLASS = "org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction"; private static final String ENHANCE_CLASS = "org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction";
private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.spring.webflux.v5.webclient.WebFluxWebClientInterceptor"; private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.spring.webflux.v5.webclient.WebFluxWebClientInterceptor";
...@@ -44,16 +44,16 @@ public class WebFluxWebClientInstrumentation extends ClassEnhancePluginDefine { ...@@ -44,16 +44,16 @@ public class WebFluxWebClientInstrumentation extends ClassEnhancePluginDefine {
} }
@Override @Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { public InstanceMethodsInterceptV2Point[] getInstanceMethodsInterceptV2Points() {
return new InstanceMethodsInterceptPoint[]{ return new InstanceMethodsInterceptV2Point[]{
new InstanceMethodsInterceptPoint() { new InstanceMethodsInterceptV2Point() {
@Override @Override
public ElementMatcher<MethodDescription> getMethodsMatcher() { public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("exchange"); return named("exchange");
} }
@Override @Override
public String getMethodsInterceptor() { public String getMethodsInterceptorV2() {
return INTERCEPT_CLASS; return INTERCEPT_CLASS;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册