You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2019/09/18 01:55:15 UTC

[GitHub] [skywalking] stevehu commented on a change in pull request #3323: Add Light4j plugin

stevehu commented on a change in pull request #3323: Add Light4j plugin
URL: https://github.com/apache/skywalking/pull/3323#discussion_r325453199
 
 

 ##########
 File path: apm-sniffer/apm-sdk-plugin/light4j-plugins/light4j-plugin/src/main/java/org/apache/skywalking/apm/plugin/light4j/HandleRequestInterceptor.java
 ##########
 @@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.light4j;
+
+import com.networknt.exception.ExceptionHandler;
+import com.networknt.handler.MiddlewareHandler;
+import com.networknt.handler.OrchestrationHandler;
+import io.undertow.server.HttpServerExchange;
+import io.undertow.util.HeaderMap;
+import org.apache.skywalking.apm.agent.core.conf.Config;
+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.ContextSnapshot;
+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.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 java.lang.reflect.Method;
+
+/**
+ * {@link HandleRequestInterceptor} creates an entry span before the execution of
+ * {@link com.networknt.exception.ExceptionHandler#handleRequest(HttpServerExchange)} in the I/O thread.
+ *
+ * If the {@link Config.Plugin.Light4J#TRACE_HANDLER_CHAIN} flag is set, additionally a local span is produced for each
+ * {@link com.networknt.handler.MiddlewareHandler} and business handler before their respective
+ * {@link com.networknt.handler.LightHttpHandler#handleRequest(HttpServerExchange)} method executes.
+ * Since {@link com.networknt.handler.LightHttpHandler} is implemented by various middleware and business handlers and
+ * the Light4J framework delegates to these in succession, a chain of
+ * {@link org.apache.skywalking.apm.agent.core.context.trace.LocalSpan}s will be produced.
+ *
+ * @author tsuilouis
+ */
+public class HandleRequestInterceptor implements InstanceMethodsAroundInterceptor {
+
+    @Override
+    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+                             MethodInterceptResult result) {
+        if (isExceptionHandler(objInst)) {
+            HttpServerExchange exchange = (HttpServerExchange) allArguments[0];
+
+            if (exchange.isInIoThread()) {
+
+                String operationName = exchange.getRequestPath() + "@" + exchange.getRequestMethod();
 
 Review comment:
   In spring, one controller can handle multiple requests with different HTTP verbs and I think it makes sense to have the format that supports multiple verbs. Light-4j is targeted to microservices and each endpoint will have only one verb and path combined and list of middleware handlers and business handlers. As we are supporting other tracing product like Jaeger and planning to support others. It makes sense to use the Light-4j endpoint for us as our users are familiar with the path@verb formation. What do you think?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services