提交 77019ba6 编写于 作者: V viswaramamoorthy 提交者: wu-sheng

Rabbitmq instrument consumer class correctly to get duration reported accurately (#3761)

上级 554df44a
......@@ -40,8 +40,8 @@ public class RabbitMQConsumerInterceptor implements InstanceMethodsAroundInterce
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
ContextCarrier contextCarrier = new ContextCarrier();
String url = (String) objInst.getSkyWalkingDynamicField();
Envelope envelope = (Envelope) allArguments[2];
AMQP.BasicProperties properties = (AMQP.BasicProperties) allArguments[3];
Envelope envelope = (Envelope) allArguments[1];
AMQP.BasicProperties properties = (AMQP.BasicProperties) allArguments[2];
AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + "Topic/" + envelope.getExchange() + "Queue/" + envelope.getRoutingKey() + CONSUMER_OPERATE_NAME_SUFFIX, null).start(System.currentTimeMillis());
Tags.MQ_BROKER.set(activeSpan,url);
Tags.MQ_TOPIC.set(activeSpan,envelope.getExchange());
......
......@@ -21,17 +21,18 @@ package org.apache.skywalking.apm.plugin.rabbitmq.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.DeclaredInstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
public class RabbitMQConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.rabbitmq.RabbitMQConsumerInterceptor";
public static final String ENHANCE_CLASS_PRODUCER = "com.rabbitmq.client.impl.ConsumerDispatcher";
public static final String ENHANCE_CLASS_PRODUCER = "com.rabbitmq.client.Consumer";
public static final String ENHANCE_METHOD_DISPATCH = "handleDelivery";
public static final String INTERCEPTOR_CONSTRUCTOR = "org.apache.skywalking.apm.plugin.rabbitmq.RabbitMQProducerAndConsumerConstructorInterceptor";
@Override
......@@ -52,9 +53,9 @@ public class RabbitMQConsumerInstrumentation extends ClassInstanceMethodsEnhance
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
new DeclaredInstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(ENHANCE_METHOD_DISPATCH).and(takesArgumentWithType(3,"com.rabbitmq.client.AMQP$BasicProperties"));
return named(ENHANCE_METHOD_DISPATCH).and(takesArgumentWithType(2,"com.rabbitmq.client.AMQP$BasicProperties"));
}
......@@ -63,7 +64,7 @@ public class RabbitMQConsumerInstrumentation extends ClassInstanceMethodsEnhance
}
@Override public boolean isOverrideArgs() {
return true;
return false;
}
}
};
......@@ -71,6 +72,6 @@ public class RabbitMQConsumerInstrumentation extends ClassInstanceMethodsEnhance
@Override
protected ClassMatch enhanceClass() {
return MultiClassNameMatch.byMultiClassMatch(ENHANCE_CLASS_PRODUCER);
return HierarchyMatch.byHierarchyMatch(new String[] {ENHANCE_CLASS_PRODUCER});
}
}
......@@ -74,7 +74,7 @@ public class RabbitMQConsumerInterceptorTest {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("sw6","1-MS4xLjE1NDM5NzU1OTEwMTQwMDAx-MS4xLjE1NDM5NzU1OTA5OTcwMDAw-0-1-1-IzEyNy4wLjAuMTo1Mjcy-I1JhYmJpdE1RL1RvcGljL1F1ZXVlL3JhYmJpdG1xLXRlc3QvUHJvZHVjZXI=-I1JhYmJpdE1RL1RvcGljL1F1ZXVlL3JhYmJpdG1xLXRlc3QvUHJvZHVjZXI=");
AMQP.BasicProperties.Builder propsBuilder = new AMQP.BasicProperties.Builder();
Object[] arguments = new Object[] {0,0,envelope,propsBuilder.headers(headers).build()};
Object[] arguments = new Object[] {0,envelope,propsBuilder.headers(headers).build()};
rabbitMQConsumerInterceptor.beforeMethod(enhancedInstance,null,arguments,null,null);
rabbitMQConsumerInterceptor.afterMethod(enhancedInstance,null,arguments,null,null);
......@@ -86,7 +86,7 @@ public class RabbitMQConsumerInterceptorTest {
public void testRabbitMQConsumerInterceptorWithNilHeaders() throws Throwable {
Envelope envelope = new Envelope(1111,false,"","rabbitmq-test");
AMQP.BasicProperties.Builder propsBuilder = new AMQP.BasicProperties.Builder();
Object[] arguments = new Object[] {0,0,envelope,propsBuilder.headers(null).build()};
Object[] arguments = new Object[] {0,envelope,propsBuilder.headers(null).build()};
rabbitMQConsumerInterceptor.beforeMethod(enhancedInstance,null,arguments,null,null);
rabbitMQConsumerInterceptor.afterMethod(enhancedInstance,null,arguments,null,null);
......@@ -99,7 +99,7 @@ public class RabbitMQConsumerInterceptorTest {
Envelope envelope = new Envelope(1111,false,"","rabbitmq-test");
Map<String, Object> headers = new HashMap<String, Object>();
AMQP.BasicProperties.Builder propsBuilder = new AMQP.BasicProperties.Builder();
Object[] arguments = new Object[] {0,0,envelope,propsBuilder.headers(headers).build()};
Object[] arguments = new Object[] {0,envelope,propsBuilder.headers(headers).build()};
rabbitMQConsumerInterceptor.beforeMethod(enhancedInstance,null,arguments,null,null);
rabbitMQConsumerInterceptor.afterMethod(enhancedInstance,null,arguments,null,null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册