wu-sheng commented on a change in pull request #3945: Enhance webflux plugin, related to Spring Gateway plugin too. URL: https://github.com/apache/skywalking/pull/3945#discussion_r352462478
########## File path: apm-sniffer/optional-plugins/optional-spring-plugins/spring-webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/reactive/DispatcherHandlerHandleMethodInterceptor.java ########## @@ -16,62 +16,93 @@ * */ -package org.apache.skywalking.apm.plugin.spring.webflux.v5; - -/** - * @author zhaoyuguang - */ +package org.apache.skywalking.apm.plugin.spring.webflux.v5.reactive; +import java.lang.reflect.Method; +import java.util.List; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.context.AbstractTracerContext; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; -import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService; import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.tag.Tags.HTTP; 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.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.MethodInterceptResult; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchangeDecorator; import org.springframework.web.server.adapter.DefaultServerWebExchange; +import reactor.core.publisher.Mono; -import java.lang.reflect.Method; -import java.util.List; - +/** + * @author Born + */ public class DispatcherHandlerHandleMethodInterceptor implements InstanceMethodsAroundInterceptor { - private static final String WIP_OPERATION_NAME = "WEBFLUX.handle"; + private ContextManagerExtendService extendService = ServiceManager.INSTANCE.findService(ContextManagerExtendService.class); @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { - EnhancedInstance instance = DispatcherHandlerHandleMethodInterceptor.getInstance(allArguments[0]); - if (instance != null) { - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - ServerWebExchange exchange = (ServerWebExchange) allArguments[0]; - HttpHeaders headers = exchange.getRequest().getHeaders(); - while (next.hasNext()) { - next = next.next(); - List<String> header = headers.get(next.getHeadKey()); - if (header != null && header.size() > 0) { - next.setHeadValue(header.get(0)); - } - } - AbstractSpan span = ContextManager.createEntrySpan(WIP_OPERATION_NAME, contextCarrier); - span.setComponent(ComponentsDefine.SPRING_WEBFLUX); - SpanLayer.asHttp(span); - Tags.URL.set(span, exchange.getRequest().getURI().toString()); - instance.setSkyWalkingDynamicField(span); - } + } @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { - return ret; + EnhancedInstance instance = getInstance(allArguments[0]); + + ServerWebExchange exchange = (ServerWebExchange) allArguments[0]; + + ContextCarrier carrier = new ContextCarrier(); + CarrierItem next = carrier.items(); + HttpHeaders headers = exchange.getRequest().getHeaders(); + while (next.hasNext()) { + next = next.next(); + List<String> header = headers.get(next.getHeadKey()); + if (header != null && header.size() > 0) { + next.setHeadValue(header.get(0)); + } + } + + String pathStr = exchange.getRequest().getPath().value(); + String methodStr = exchange.getRequest().getMethodValue(); Review comment: This will be overridden by SpringMVC plugin if it is activated. We are using Spring Controller pattern today. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services