[GitHub] [skywalking] tsuilouis commented on a change in pull request #3323: Add Light4j plugin
tsuilouis commented on a change in pull request #3323: Add Light4j plugin URL: https://github.com/apache/skywalking/pull/3323#discussion_r325469781 ## 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(); +final HeaderMap headers = exchange.getRequestHeaders(); +final ContextCarrier contextCarrier = new ContextCarrier(); + +CarrierItem next = contextCarrier.items(); +while (next.hasNext()) { +next = next.next(); +next.setHeadValue(headers.getFirst(next.getHeadKey())); +} + +AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); +Tags.URL.set(span, exchange.getRequestURL()); +Tags.HTTP.METHOD.set(span, exchange.getRequestMethod().toString()); +span.setComponent(ComponentsDefine.LIGHT_4J); Review comment: Ok, I have added a commit with the submodule update at https://github.com/apache/skywalking/pull/3323/commits/efde0fff50ddf44bb78f3e25b6d0ccd6f7c38d2f. 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:
[GitHub] [skywalking] tsuilouis commented on a change in pull request #3323: Add Light4j plugin
tsuilouis commented on a change in pull request #3323: Add Light4j plugin URL: https://github.com/apache/skywalking/pull/3323#discussion_r325436372 ## 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: Just to clarify using your example, if the request sent is `GET /a/b/c` you would like to see the op name as just `{GET} /a/b/c` and not `{PUT, GET} /a/b/c`, correct? 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
[GitHub] [skywalking] tsuilouis commented on a change in pull request #3323: Add Light4j plugin
tsuilouis commented on a change in pull request #3323: Add Light4j plugin URL: https://github.com/apache/skywalking/pull/3323#discussion_r325431072 ## 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(); +final HeaderMap headers = exchange.getRequestHeaders(); +final ContextCarrier contextCarrier = new ContextCarrier(); + +CarrierItem next = contextCarrier.items(); +while (next.hasNext()) { +next = next.next(); +next.setHeadValue(headers.getFirst(next.getHeadKey())); +} + +AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); +Tags.URL.set(span, exchange.getRequestURL()); +Tags.HTTP.METHOD.set(span, exchange.getRequestMethod().toString()); +span.setComponent(ComponentsDefine.LIGHT_4J); Review comment: Ok, I have submitted the PR at https://github.com/apache/skywalking-rocketbot-ui/pull/157. 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
[GitHub] [skywalking] tsuilouis commented on a change in pull request #3323: Add Light4j plugin
tsuilouis commented on a change in pull request #3323: Add Light4j plugin URL: https://github.com/apache/skywalking/pull/3323#discussion_r325417646 ## File path: docs/en/setup/service-agent/java-agent/README.md ## @@ -102,6 +102,7 @@ property key | Description | Default | `plugin.solrj.trace_statement`|If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false.|`false`| `plugin.solrj.trace_ops_params`|If true, trace all the operation parameters in Solr request, default is false.|`false`| `plugin.opgroup.*`|Support operation name customize group rules in different plugins. Read [Group rule supported plugins](op_name_group_rule.md)|Not set| +`plugin.light4j.trace_handler_chain`|If true, trace all middleware/business handlers that are part of the Light4J handler chain for a request.|false| Review comment: Ok, done in commit https://github.com/apache/skywalking/pull/3323/commits/2a05e78e5e55b1f91a1ba2e20aa4e35552283a9e 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
[GitHub] [skywalking] tsuilouis commented on a change in pull request #3323: Add Light4j plugin
tsuilouis commented on a change in pull request #3323: Add Light4j plugin URL: https://github.com/apache/skywalking/pull/3323#discussion_r325417646 ## File path: docs/en/setup/service-agent/java-agent/README.md ## @@ -102,6 +102,7 @@ property key | Description | Default | `plugin.solrj.trace_statement`|If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false.|`false`| `plugin.solrj.trace_ops_params`|If true, trace all the operation parameters in Solr request, default is false.|`false`| `plugin.opgroup.*`|Support operation name customize group rules in different plugins. Read [Group rule supported plugins](op_name_group_rule.md)|Not set| +`plugin.light4j.trace_handler_chain`|If true, trace all middleware/business handlers that are part of the Light4J handler chain for a request.|false| Review comment: Ok, done. 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
[GitHub] [skywalking] tsuilouis commented on a change in pull request #3323: Add Light4j plugin
tsuilouis commented on a change in pull request #3323: Add Light4j plugin URL: https://github.com/apache/skywalking/pull/3323#discussion_r325288071 ## 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: The op name looks like "/v1/pets@GET". This is the format that light-4j uses with Jaeger implementation of OpenTracing: https://github.com/networknt/light-4j/blob/master/jaeger-tracing/src/main/java/com/networknt/jaeger/tracing/JaegerHandler.java#L79. I would like to keep the HTTP verb in the op name, but I am open to changing to the rest of the format. 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