Skip to content

Commit be5d5a3

Browse files
committed
Update spring rabbitmq plugin
1 parent 663704c commit be5d5a3

File tree

29 files changed

+35
-520
lines changed

29 files changed

+35
-520
lines changed

.github/workflows/plugins-jdk17-test.0.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
- jetty-11.x-scenario
8181
- jetty-10.x-scenario
8282
- spring-ai-1.x-scenario
83-
- spring-rabbitmq-3.x-4.x-scenario
83+
- spring-rabbitmq-scenario
8484
steps:
8585
- uses: actions/checkout@v2
8686
with:

.github/workflows/plugins-test.3.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ jobs:
9696
- spring-kafka-1.3.x-scenario
9797
- spring-kafka-2.2.x-scenario
9898
- spring-kafka-2.3.x-scenario
99-
- spring-rabbitmq-2.x-scenario
10099
- spring-scheduled-3.x-5.x-scenario
101100
- elasticjob-2.x-scenario
102101
- quartz-scheduler-2.x-scenario

apm-sniffer/apm-sdk-plugin/rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/rabbitmq/RabbitMQConsumerInterceptor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626

2727
public class RabbitMQConsumerInterceptor implements InstanceMethodsAroundInterceptor {
2828

29+
public static final String INTERNAL_CONSUMER_CLASS_NAME = "org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$InternalConsumer";
30+
2931
@Override
3032
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
3133
MethodInterceptResult result) throws Throwable {
32-
if (Thread.currentThread().getName().toLowerCase().contains("springframework")) {
34+
Consumer consumer = (Consumer) allArguments[6];
35+
if (consumer != null && INTERNAL_CONSUMER_CLASS_NAME.equals(consumer.getClass().getName())) {
3336
return;
3437
}
35-
Consumer consumer = (Consumer) allArguments[6];
3638
allArguments[6] = new TracerConsumer(consumer, (String) objInst.getSkyWalkingDynamicField());
3739
}
3840

apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/SpringRabbitMQConsumerInterceptor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@
2828
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
2929
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
3030
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
31-
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
32-
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
31+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.InstanceMethodsAroundInterceptorV2;
32+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.MethodInvocationContext;
3333
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
3434
import org.springframework.amqp.core.Message;
3535
import org.springframework.amqp.core.MessageProperties;
3636

3737
import com.rabbitmq.client.Channel;
3838
import com.rabbitmq.client.Connection;
3939

40-
public class SpringRabbitMQConsumerInterceptor implements InstanceMethodsAroundInterceptor {
40+
public class SpringRabbitMQConsumerInterceptor implements InstanceMethodsAroundInterceptorV2 {
4141
public static final String OPERATE_NAME_PREFIX = "RabbitMQ/";
4242
public static final String CONSUMER_OPERATE_NAME_SUFFIX = "/Consumer";
4343

4444
@Override
4545
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
46-
MethodInterceptResult result) throws Throwable {
46+
MethodInvocationContext context) throws Throwable {
4747
Channel channel = (Channel) allArguments[0];
4848
Message message = (Message) allArguments[1];
4949
MessageProperties messageProperties = message.getMessageProperties();
@@ -72,14 +72,14 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
7272

7373
@Override
7474
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
75-
Object ret) throws Throwable {
75+
Object ret, MethodInvocationContext context) throws Throwable {
7676
ContextManager.stopSpan();
7777
return ret;
7878
}
7979

8080
@Override
8181
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
82-
Class<?>[] argumentsTypes, Throwable t) {
82+
Class<?>[] argumentsTypes, Throwable t, MethodInvocationContext context) {
8383
ContextManager.activeSpan().log(t);
8484
}
8585
}

apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/define/SpringRabbitMQConsumerInstrumentation.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
import static net.bytebuddy.matcher.ElementMatchers.named;
2222

2323
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
24-
import org.apache.skywalking.apm.agent.core.plugin.interceptor.DeclaredInstanceMethodsInterceptPoint;
25-
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
26-
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
24+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.ClassInstanceMethodsEnhancePluginDefineV2;
25+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.v2.DeclaredInstanceMethodsInterceptV2Point;
26+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.v2.InstanceMethodsInterceptV2Point;
2727
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2828
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
2929

3030
import net.bytebuddy.description.method.MethodDescription;
3131
import net.bytebuddy.matcher.ElementMatcher;
3232

33-
public class SpringRabbitMQConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
33+
public class SpringRabbitMQConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefineV2 {
3434
public static final String ENHANCE_CLASS = "org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer";
3535
public static final String ENHANCE_METHOD = "executeListener";
3636
public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.rabbitmq.SpringRabbitMQConsumerInterceptor";
@@ -41,16 +41,16 @@ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
4141
}
4242

4343
@Override
44-
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
45-
return new InstanceMethodsInterceptPoint[] {
46-
new DeclaredInstanceMethodsInterceptPoint() {
44+
public InstanceMethodsInterceptV2Point[] getInstanceMethodsInterceptV2Points() {
45+
return new InstanceMethodsInterceptV2Point[] {
46+
new DeclaredInstanceMethodsInterceptV2Point() {
4747
@Override
4848
public ElementMatcher<MethodDescription> getMethodsMatcher() {
4949
return named(ENHANCE_METHOD);
5050
}
5151

5252
@Override
53-
public String getMethodsInterceptor() {
53+
public String getMethodsInterceptorV2() {
5454
return INTERCEPTOR_CLASS;
5555
}
5656

apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/RabbitMQSpringConsumerInterceptorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void setUp() throws Exception {
6969
public void testRabbitMQConsumerInterceptorWithNilHeaders() throws Throwable {
7070
Object[] args = prepareMockData(false);
7171
rabbitMQConsumerInterceptor.beforeMethod(enhancedInstance, null, args, new Class[0], null);
72-
rabbitMQConsumerInterceptor.afterMethod(enhancedInstance, null, args, new Class[0], null);
72+
rabbitMQConsumerInterceptor.afterMethod(enhancedInstance, null, args, new Class[0], null, null);
7373
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
7474
Assert.assertThat(traceSegments.size(), is(1));
7575
}
@@ -78,7 +78,7 @@ public void testRabbitMQConsumerInterceptorWithNilHeaders() throws Throwable {
7878
public void testRabbitMQConsumerInterceptor() throws Throwable {
7979
Object[] args = prepareMockData(true);
8080
rabbitMQConsumerInterceptor.beforeMethod(enhancedInstance, null, args, new Class[0], null);
81-
rabbitMQConsumerInterceptor.afterMethod(enhancedInstance, null, args, new Class[0], null);
81+
rabbitMQConsumerInterceptor.afterMethod(enhancedInstance, null, args, new Class[0], null, null);
8282
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
8383
Assert.assertThat(traceSegments.size(), is(1));
8484
}

docs/en/setup/service-agent/java-agent/Supported-list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ metrics based on the tracing data.
8080
* [Spring-Kafka](https://github.com/spring-projects/spring-kafka) Spring Kafka Consumer 1.3.x -> 2.3.x (2.0.x and 2.1.x not tested and not recommended by [the official document](https://spring.io/projects/spring-kafka))
8181
* [ActiveMQ](https://github.com/apache/activemq) 5.10.0 -> 5.15.4
8282
* [RabbitMQ](https://www.rabbitmq.com/) 3.x-> 5.x
83+
* [Spring-RabbitMQ](https://github.com/spring-projects/spring-amqp) 2.x -> 4.x
8384
* [Pulsar](http://pulsar.apache.org) 2.2.x -> 2.9.x
8485
* [NATS](https://github.com/nats-io/nats.java) 2.14.x -> 2.16.5
8586
* [ActiveMQ-Artemis](https://github.com/apache/activemq) 2.30.0 -> 2.31.2

test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml

Lines changed: 0 additions & 117 deletions
This file was deleted.

test/plugin/scenarios/spring-rabbitmq-2.x-scenario/support-version.list

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/bin/startup.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)