wu-sheng commented on a change in pull request #6837:
URL: https://github.com/apache/skywalking/pull/6837#discussion_r620083082



##########
File path: 
apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/ConsumerConstructorInterceptor.java
##########
@@ -22,18 +22,49 @@
 import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
 import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
 /**
- *
+ * @author zhang xin, stalary
  **/
 public class ConsumerConstructorInterceptor implements 
InstanceConstructorInterceptor {
 
-    @Override
-    public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
-        ConsumerConfig config = (ConsumerConfig) allArguments[0];
-        // set the bootstrap server address
-        ConsumerEnhanceRequiredInfo requiredInfo = new 
ConsumerEnhanceRequiredInfo();
-        requiredInfo.setBrokerServers(config.getList("bootstrap.servers"));
-        requiredInfo.setGroupId(config.getString("group.id"));
+    @Override public void onConstruct(EnhancedInstance objInst, Object[] 
allArguments) {
+        ConsumerEnhanceRequiredInfo requiredInfo = 
resolveConsumerEnhanceRequiredInfo( allArguments[0] );
         objInst.setSkyWalkingDynamicField(requiredInfo);
     }
+
+    private ConsumerEnhanceRequiredInfo resolveConsumerEnhanceRequiredInfo( 
Object configArgument )
+    {
+        ConsumerEnhanceRequiredInfo requiredInfo = new 
ConsumerEnhanceRequiredInfo();
+
+        if(configArgument instanceof ConsumerConfig) {
+            ConsumerConfig config = (ConsumerConfig) configArgument;
+            // set the bootstrap server address
+            requiredInfo.setBrokerServers(config.getList("bootstrap.servers"));
+            requiredInfo.setGroupId(config.getString("group.id"));
+        } else if (configArgument instanceof Map ) {

Review comment:
       This ConsumerConfig and Map logic should be separated into 2 
interceptors, rather than using `instanceof` to check.
   Even here, we should not face performance impact as this is `KafkaConsumer` 
initialization, so wouldn't execute in high frequency, but still, better to 
avoid any tiny performance impact. 
   @kezhenxu94 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:
[email protected]


Reply via email to