wu-sheng commented on code in PR #697: URL: https://github.com/apache/skywalking-java/pull/697#discussion_r1657073154
########## apm-sniffer/apm-sdk-plugin/solon-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solon/SolonActionExecuteInterceptor.java: ########## @@ -0,0 +1,94 @@ +/* + * 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.solon; + +import lombok.extern.slf4j.Slf4j; +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.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 org.apache.skywalking.apm.util.StringUtil; +import org.noear.solon.core.handle.Context; + +import java.lang.reflect.Method; + +@Slf4j +public class SolonActionExecuteInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Context ctx = (Context) allArguments[0]; + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(ctx.header(next.getHeadKey())); + } + String operationName = "Solon:" + ctx.method() + ":" + ctx.path(); + AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); + span.setComponent(ComponentsDefine.SOLON_MVC); + SpanLayer.asHttp(span); + Tags.URL.set(span, ctx.url()); + Tags.HTTP.METHOD.set(span, ctx.method()); + String headerStr = ctx.headerMap().toString(); + if (headerStr.length() > 1024) { + headerStr = headerStr.substring(0, 1024); + } + Tags.HTTP.HEADERS.set(span, headerStr); + String body = ctx.body(); + if (StringUtil.isNotBlank(body)) { + if (body.length() > 1024) { + body = body.substring(0, 1024); + } + Tags.HTTP.BODY.set(span, body); + } + String param = ctx.paramMap().toString(); + if (param.length() > 1024) { + param = param.substring(0, 1024); + } + Tags.HTTP.PARAMS.set(span, param); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, + Object ret) { + Context ctx = (Context) allArguments[0]; + if (ctx.errors != null) { + Tags.HTTP_RESPONSE_STATUS_CODE.set(ContextManager.activeSpan(), 500); + } else { Review Comment: Is this framework not responding the official HTTP status code? ########## apm-sniffer/apm-sdk-plugin/solon-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solon/SolonActionExecuteInterceptor.java: ########## @@ -0,0 +1,94 @@ +/* + * 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.solon; + +import lombok.extern.slf4j.Slf4j; +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.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 org.apache.skywalking.apm.util.StringUtil; +import org.noear.solon.core.handle.Context; + +import java.lang.reflect.Method; + +@Slf4j +public class SolonActionExecuteInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Context ctx = (Context) allArguments[0]; + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(ctx.header(next.getHeadKey())); + } + String operationName = "Solon:" + ctx.method() + ":" + ctx.path(); + AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); + span.setComponent(ComponentsDefine.SOLON_MVC); + SpanLayer.asHttp(span); + Tags.URL.set(span, ctx.url()); + Tags.HTTP.METHOD.set(span, ctx.method()); + String headerStr = ctx.headerMap().toString(); + if (headerStr.length() > 1024) { + headerStr = headerStr.substring(0, 1024); + } + Tags.HTTP.HEADERS.set(span, headerStr); + String body = ctx.body(); + if (StringUtil.isNotBlank(body)) { + if (body.length() > 1024) { + body = body.substring(0, 1024); + } + Tags.HTTP.BODY.set(span, body); + } + String param = ctx.paramMap().toString(); + if (param.length() > 1024) { + param = param.substring(0, 1024); + } + Tags.HTTP.PARAMS.set(span, param); Review Comment: Header and Body collection should be optional, and have a configuration to control it.(default OFF) Otherwise, you would impact the target system performance seriously. ########## test/plugin/scenarios/solon-2.x-scenario/config/expectedData.yaml: ########## @@ -0,0 +1,118 @@ +# 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. + +segmentItems: + - serviceName: solon-2.x-scenario + segmentSize: 3 Review Comment: ```suggestion segmentSize: ge 3 ``` I think there should be not always 3, right? ########## test/plugin/scenarios/solon-2.x-scenario/config/expectedData.yaml: ########## @@ -0,0 +1,118 @@ +# 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. + +segmentItems: + - serviceName: solon-2.x-scenario + segmentSize: 3 + segments: + - segmentId: not null + spans: + - operationName: Solon:HEAD:/testcase/healthCheck Review Comment: `/healthCheck` should not be included, as this is not a part of tracing test. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
