wallezhang commented on a change in pull request #6774: URL: https://github.com/apache/skywalking/pull/6774#discussion_r617471662
########## File path: apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerListenerInterceptor.java ########## @@ -0,0 +1,86 @@ +/* + * 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.pulsar; + +import org.apache.pulsar.client.api.Message; +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 java.lang.reflect.Method; + +/** + * Interceptor for pulsar consumer message listener enhanced instance + * <p> + * Here is the intercept process steps: + * + * <pre> + * 1. Get @{@link ContextCarrier} from message + * 2. Create a local span when call <code>received</code> method + * 3. Extract trace information from context carrier + * 4. Stop the local span when <code>received</code> method finished. + * </pre> + */ +public class PulsarConsumerListenerInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String CONSUMER_OPERATE_NAME = "Pulsar/Consumer/MessageListener"; Review comment: I know what you mean, but in most cases, we will write the business code directly in the `MessageListener`, therefore it is not a span of message reception, but more like a process of message handling, such as ``` // span Pulsar/Consumer start Message message = consumer.receive(); // List<Message> messages = consumer.batchReceive(); // span Pulsar/Consumer end // business code, maybe start a new span named HandleMessage // do some business logic with message... consumer.acknowledge(message); // business code end, and the HandleMessage span is end ``` And with `MessageListener`, we will do the business logic like this ``` pulsarClient.newConsumer().topic("test").subscriptionName("test").messageListener((consumer,message) -> { // span Pulsar/Consumer/MessageListener start // do some business logic with message... consumer.acknowledge(message); // span Pulsar/Consumer/MessageListener end }) ``` Span `Pulsar/Consumer` is finished in client internal, and the `Pulsar/Consumer/MessageListener` is a `Local` span that represent the business logic processing. So I agree with adding a new span with `Pulsar/Consumer` span as parent. -- 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: [email protected]
