CzyerChen commented on code in PR #665:
URL: https://github.com/apache/skywalking-java/pull/665#discussion_r1459206495


##########
apm-sniffer/apm-sdk-plugin/rocketMQ-client-java-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/client/java/v5/MessageSendAsyncInterceptor.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.rocketMQ.client.java.v5;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import org.apache.rocketmq.client.apis.message.Message;
+import org.apache.rocketmq.client.apis.message.MessageBuilder;
+import org.apache.rocketmq.client.apis.producer.SendReceipt;
+import org.apache.rocketmq.client.java.impl.ClientImpl;
+import org.apache.rocketmq.client.java.message.MessageBuilderImpl;
+import org.apache.rocketmq.shaded.com.google.gson.Gson;
+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.agent.core.util.CollectionUtil;
+import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import org.apache.skywalking.apm.util.StringUtil;
+
+/**
+ * {@link MessageSendAsyncInterceptor} create exit span when the method {@link 
org.apache.rocketmq.client.java.impl.producer.ProducerImpl#sendAsync(org.apache.rocketmq.client.apis.message.Message)}
+ * execute
+ */
+public class MessageSendAsyncInterceptor implements 
InstanceMethodsAroundInterceptor {
+
+    public static final String ASYNC_SEND_OPERATION_NAME_PREFIX = "RocketMQ/";
+    public static final Gson GSON = new Gson();
+
+    @Override
+    public void beforeMethod(EnhancedInstance objInst,
+                             Method method,
+                             Object[] allArguments,
+                             Class<?>[] argumentsTypes,
+                             MethodInterceptResult result) throws Throwable {
+        Message message = (Message) allArguments[0];
+        ClientImpl producerImpl = (ClientImpl) objInst;
+
+        ContextCarrier contextCarrier = new ContextCarrier();
+        String namingServiceAddress = 
producerImpl.getClientConfiguration().getEndpoints();
+        AbstractSpan span = ContextManager.createExitSpan(
+            buildOperationName(message.getTopic()), contextCarrier, 
namingServiceAddress);
+        span.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER);
+        Tags.MQ_BROKER.set(span, namingServiceAddress);
+        Tags.MQ_TOPIC.set(span, message.getTopic());
+        Collection<String> keys = message.getKeys();
+        if (!CollectionUtil.isEmpty(keys)) {
+            span.tag(Tags.ofKey("mq.message.keys"), String.join(",", keys));
+        }
+        Optional<String> tag = message.getTag();
+        tag.ifPresent(s -> span.tag(Tags.ofKey("mq.message.tags"), s));

Review Comment:
   In general, different topics are used to separate different services, and 
different tags are used to separate different service segments. 
   
   usages may be:
   - 1 topic
   - 1 topic and several tags
   - several topics and  several tags 
   
   It may be easily to know the service segments by recording and showing the 
tag of message.



-- 
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: notifications-unsubscr...@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to