From fd8f52c78b0b735760766f524f858548f8492bef Mon Sep 17 00:00:00 2001
From: hyhyf <627680933@qq.com>
Date: Fri, 19 Jul 2024 16:18:44 +0800
Subject: [PATCH 1/6] Support tracking the message listener of spring jms
---
.github/workflows/plugins-test.3.yaml | 1 +
CHANGES.md | 2 +-
.../apm-sdk-plugin/spring-plugins/pom.xml | 1 +
.../spring-jms-5.x-plugin/pom.xml | 42 ++++++
.../jms/MessageListenerInterceptor.java | 76 +++++++++++
.../MessageListenerInstrumentation.java | 68 ++++++++++
.../src/main/resources/skywalking-plugin.def | 16 +++
.../service-agent/java-agent/Plugin-list.md | 3 +-
.../java-agent/Supported-list.md | 1 +
.../spring-jms-5.x-scenario/bin/startup.sh | 21 +++
.../config/expectedData.yaml | 90 ++++++++++++
.../spring-jms-5.x-scenario/configuration.yml | 30 ++++
.../scenarios/spring-jms-5.x-scenario/pom.xml | 128 ++++++++++++++++++
.../src/main/assembly/assembly.xml | 41 ++++++
.../apm/testcase/spring/jms/Application.java | 34 +++++
.../testcase/spring/jms/config/JmsConfig.java | 51 +++++++
.../spring/jms/controller/CaseController.java | 61 +++++++++
.../src/main/resources/application.yaml | 23 ++++
.../src/main/resources/log4j2.xml | 30 ++++
.../support-version.list | 18 +++
20 files changed, 735 insertions(+), 2 deletions(-)
create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/pom.xml
create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java
create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/define/MessageListenerInstrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/resources/skywalking-plugin.def
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/bin/startup.sh
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/configuration.yml
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/pom.xml
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/src/main/assembly/assembly.xml
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/Application.java
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/config/JmsConfig.java
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/controller/CaseController.java
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/src/main/resources/application.yaml
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/src/main/resources/log4j2.xml
create mode 100644 test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
diff --git a/.github/workflows/plugins-test.3.yaml b/.github/workflows/plugins-test.3.yaml
index 5960da690a..7065a3a0e8 100644
--- a/.github/workflows/plugins-test.3.yaml
+++ b/.github/workflows/plugins-test.3.yaml
@@ -108,6 +108,7 @@ jobs:
- shenyu-2.4.x-grpc-scenario
- shenyu-2.4.x-sofarpc-scenario
- solon-2.x-scenario
+ - spring-jms-5.x-scenario
steps:
- uses: actions/checkout@v2
with:
diff --git a/CHANGES.md b/CHANGES.md
index 623b5015f1..5a04e0b1b7 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -22,7 +22,7 @@ Release Notes.
* Improve 4x performance of ContextManagerExtendService.createTraceContext()
* Add a plugin that supports the Solon framework.
* Fixed issues in the MySQL component where the executeBatch method could result in empty SQL statements .
-
+* Add a plugin that supports the spring jms 5.x.
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/213?closed=1)
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml
index 64abfdb7eb..c089d4a5ef 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml
@@ -45,6 +45,7 @@
spring-webflux-5.x-webclient-pluginspring-webflux-6.x-webclient-pluginresttemplate-commons
+ spring-jms-5.x-pluginpom
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/pom.xml
new file mode 100644
index 0000000000..85e949cc5c
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/pom.xml
@@ -0,0 +1,42 @@
+
+
+
+ 4.0.0
+
+
+ org.apache.skywalking
+ spring-plugins
+ 9.3.0-SNAPSHOT
+
+
+ apm-spring-jms-5.x-plugin
+
+
+ 1.1.1
+
+
+
+
+ org.apache.geronimo.specs
+ geronimo-jms_1.1_spec
+ ${geronimo-jms.version}
+ provided
+
+
+
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java
new file mode 100644
index 0000000000..deb6c4e7fe
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java
@@ -0,0 +1,76 @@
+/*
+ * 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.spring.jms;
+
+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.trace.AbstractSpan;
+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 javax.jms.Message;
+import java.lang.reflect.Method;
+
+public class MessageListenerInterceptor implements InstanceMethodsAroundInterceptor {
+
+ private static final String OPERATION_NAME_PREFIX = "Jms/";
+ private static final String OPERATION_NAME_SUFFIX = "/Execute";
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst,
+ Method method,
+ Object[] allArguments, Class>[] argumentsTypes,
+ MethodInterceptResult result) throws Throwable {
+ Message message = (Message) allArguments[1];
+ ContextCarrier contextCarrier = new ContextCarrier();
+ CarrierItem next = contextCarrier.items();
+ while (next.hasNext()) {
+ next = next.next();
+ Object propertyValue = message.getStringProperty(next.getHeadKey());
+ if (propertyValue != null) {
+ next.setHeadValue(propertyValue.toString());
+ }
+ }
+ AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATION_NAME_PREFIX + message.getJMSDestination() + OPERATION_NAME_SUFFIX, null);
+ activeSpan.setComponent(ComponentsDefine.SPRING_ASYNC);
+ ContextManager.extract(contextCarrier);
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst,
+ Method method,
+ Object[] allArguments,
+ Class>[] argumentsTypes,
+ Object ret) throws Throwable {
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst,
+ Method method,
+ Object[] allArguments,
+ Class>[] argumentsTypes,
+ Throwable t) {
+ ContextManager.activeSpan().log(t);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/define/MessageListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/define/MessageListenerInstrumentation.java
new file mode 100644
index 0000000000..b8dfd3609b
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/define/MessageListenerInstrumentation.java
@@ -0,0 +1,68 @@
+/*
+ * 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.spring.jms.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.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 static net.bytebuddy.matcher.ElementMatchers.named;
+
+public class MessageListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+
+ private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.jms.MessageListenerInterceptor";
+ public static final String ENHANCE_CLASS = "org.springframework.jms.listener.AbstractMessageListenerContainer";
+ public static final String ENHANCE_METHOD = "doExecuteListener";
+
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[0];
+ }
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named(ENHANCE_METHOD);
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return INTERCEPTOR_CLASS;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return MultiClassNameMatch.byMultiClassMatch(ENHANCE_CLASS);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/resources/skywalking-plugin.def
new file mode 100644
index 0000000000..5672b8eb77
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/resources/skywalking-plugin.def
@@ -0,0 +1,16 @@
+# 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.
+spring-jms-5.x=org.apache.skywalking.apm.plugin.spring.jms.define.MessageListenerInstrumentation
diff --git a/docs/en/setup/service-agent/java-agent/Plugin-list.md b/docs/en/setup/service-agent/java-agent/Plugin-list.md
index e15b3b1f00..83ae823688 100644
--- a/docs/en/setup/service-agent/java-agent/Plugin-list.md
+++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md
@@ -177,4 +177,5 @@
- spring-webflux-6.x-webclient
- activemq-artemis-jakarta-client-2.x
- c3p0-0.9.x
-- solon-2.x
\ No newline at end of file
+- solon-2.x
+- spring-jms-5.x
\ No newline at end of file
diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md
index c91c25d4a2..b21c8709b1 100644
--- a/docs/en/setup/service-agent/java-agent/Supported-list.md
+++ b/docs/en/setup/service-agent/java-agent/Supported-list.md
@@ -84,6 +84,7 @@ metrics based on the tracing data.
* [NATS](https://github.com/nats-io/nats.java) 2.14.x -> 2.15.x
* [ActiveMQ-Artemis](https://github.com/apache/activemq) 2.30.0 -> 2.31.2
* Aliyun ONS 1.x (Optional¹)
+ * Spring Jms 5.x
* NoSQL
* [aerospike](https://github.com/aerospike/aerospike-client-java) 3.x -> 6.x
* Redis
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/bin/startup.sh b/test/plugin/scenarios/spring-jms-5.x-scenario/bin/startup.sh
new file mode 100644
index 0000000000..4c83688bbd
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/bin/startup.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# 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.
+
+home="$(cd "$(dirname $0)"; pwd)"
+
+java -jar ${agent_opts} ${home}/../libs/spring-jms-5.x-scenario.jar &
\ No newline at end of file
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml
new file mode 100644
index 0000000000..ceecdfb29f
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml
@@ -0,0 +1,90 @@
+# 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.
+segmentItems:
+ - serviceName: spring-jms-5.x-scenario
+ segmentSize: ge 2
+ segments:
+ - segmentId: not null
+ spans:
+ - operationName: ActiveMQ/Queue/test/Producer
+ parentSpanId: 0
+ spanId: 1
+ spanLayer: MQ
+ startTime: nq 0
+ endTime: nq 0
+ componentId: 45
+ isError: false
+ spanType: Exit
+ peer: not blank
+ tags:
+ - { key: mq.broker, value: not blank }
+ - { key: mq.queue, value: test }
+ skipAnalysis: 'false'
+ - operationName: GET:/spring-jms-5.x-scenario/case/spring-jms-scenario
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Http
+ startTime: nq 0
+ endTime: nq 0
+ componentId: 1
+ isError: false
+ spanType: Entry
+ peer: ''
+ tags:
+ - { key: url, value: 'http://localhost:8080/spring-jms-5.x-scenario/case/spring-jms-scenario' }
+ - { key: http.method, value: GET }
+ - { key: http.status_code, value: '200' }
+ skipAnalysis: 'false'
+ - segmentId: not null
+ spans:
+ - operationName: ActiveMQ/Queue/test/Consumer
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: MQ
+ startTime: nq 0
+ endTime: nq 0
+ componentId: 46
+ isError: false
+ spanType: Entry
+ peer: not blank
+ tags:
+ - { key: mq.broker, value: not blank }
+ - { key: mq.queue, value: test }
+ - { key: transmission.latency, value: ge 0 }
+ refs:
+ - { parentEndpoint: GET:/spring-jms-5.x-scenario/case/spring-jms-scenario, networkAddress: not null,
+ refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null,
+ parentServiceInstance: not null, parentService: not null, traceId: not null }
+ skipAnalysis: 'false'
+ - segmentId: not null
+ spans:
+ - operationName: Jms/queue://test/Execute
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Unknown
+ startTime: nq 0
+ endTime: nq 0
+ componentId: 65
+ isError: false
+ spanType: Entry
+ peer: ''
+ tags:
+ - { key: transmission.latency, value: ge 0 }
+ refs:
+ - { parentEndpoint: GET:/spring-jms-5.x-scenario/case/spring-jms-scenario, networkAddress: not null,
+ refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null,
+ parentServiceInstance: not null, parentService: not null, traceId: not null }
+ skipAnalysis: 'false'
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/configuration.yml b/test/plugin/scenarios/spring-jms-5.x-scenario/configuration.yml
new file mode 100644
index 0000000000..f19d35f3e9
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/configuration.yml
@@ -0,0 +1,30 @@
+# 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.
+
+type: jvm
+entryService: http://localhost:8080/spring-jms-5.x-scenario/case/spring-jms-scenario
+healthCheck: http://localhost:8080/spring-jms-5.x-scenario/case/healthCheck
+withPlugins: apm-activemq-5.x-plugin-*.jar
+startScript: ./bin/startup.sh
+environment:
+ - activemq.server=tcp://activemq-server:61616
+dependencies:
+ activemq-server:
+ image: rmohr/activemq:5.14.5
+ hostname: activemq-server
+ expose:
+ - 8161
+ - 61616
\ No newline at end of file
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/pom.xml b/test/plugin/scenarios/spring-jms-5.x-scenario/pom.xml
new file mode 100644
index 0000000000..b7214ee831
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/pom.xml
@@ -0,0 +1,128 @@
+
+
+
+
+ org.apache.skywalking.apm.testcase
+ spring-jms-5.x-scenario
+ 1.0.0
+ jar
+
+ 4.0.0
+
+
+ UTF-8
+ 1.8
+ 3.8.1
+ 5.3.37
+ 2.1.6.RELEASE
+ 1.18.20
+
+
+ skywalking-spring-jms-5.x-scenario
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ ${spring.boot.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-log4j2
+ ${spring.boot.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+ org.springframework.boot
+ spring-boot-starter-activemq
+ ${spring.boot.version}
+
+
+ org.springframework
+ spring-jms
+
+
+
+
+ org.springframework
+ spring-jms
+ ${test.framework.version}
+
+
+
+
+
+ spring-jms-5.x-scenario
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ ${spring.boot.version}
+
+
+
+ repackage
+
+
+
+
+
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
+ ${compiler.version}
+ ${project.build.sourceEncoding}
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ assemble
+ package
+
+ single
+
+
+
+ src/main/assembly/assembly.xml
+
+ ./target/
+
+
+
+
+
+
+
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/assembly/assembly.xml
new file mode 100644
index 0000000000..104b14a9ac
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/assembly/assembly.xml
@@ -0,0 +1,41 @@
+
+
+
+
+ zip
+
+
+
+
+ ./bin
+ 0775
+
+
+
+
+
+
+ ./libs
+ 0775
+
+
+
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/Application.java b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/Application.java
new file mode 100644
index 0000000000..58b72178a9
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/Application.java
@@ -0,0 +1,34 @@
+/*
+ * 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.testcase.spring.jms;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ try {
+ SpringApplication.run(Application.class, args);
+ } catch (Exception e) {
+ // Never do this
+ }
+ }
+}
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/config/JmsConfig.java b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/config/JmsConfig.java
new file mode 100644
index 0000000000..0abd37673e
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/config/JmsConfig.java
@@ -0,0 +1,51 @@
+/*
+ * 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.testcase.spring.jms.config;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jms.annotation.EnableJms;
+import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
+import org.springframework.jms.config.JmsListenerContainerFactory;
+
+import javax.jms.ConnectionFactory;
+
+@Configuration
+@EnableJms
+public class JmsConfig {
+ @Value("${activemq.server}")
+ private String brokenUrl;
+ private static final String USER_NAME = ActiveMQConnection.DEFAULT_USER;
+ private static final String PASSWORD = ActiveMQConnection.DEFAULT_PASSWORD;
+
+ @Bean
+ public ConnectionFactory connectionFactory() {
+ return new ActiveMQConnectionFactory(USER_NAME, PASSWORD, brokenUrl);
+ }
+
+ @Bean
+ public JmsListenerContainerFactory> jmsListenerContainerFactory(ConnectionFactory connectionFactory) {
+ DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
+ bean.setPubSubDomain(false);
+ bean.setConnectionFactory(connectionFactory);
+ return bean;
+ }
+}
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/controller/CaseController.java b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/controller/CaseController.java
new file mode 100644
index 0000000000..196a752a06
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/jms/controller/CaseController.java
@@ -0,0 +1,61 @@
+/*
+ * 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.testcase.spring.jms.controller;
+
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jms.annotation.JmsListener;
+import org.springframework.jms.core.JmsMessagingTemplate;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+@RestController
+@RequestMapping("/case")
+@Log4j2
+public class CaseController {
+
+ private static final String SUCCESS = "Success";
+
+ @Autowired
+ private JmsMessagingTemplate jmsMessagingTemplate;
+
+ @RequestMapping("/spring-jms-scenario")
+ @ResponseBody
+ public String testcase() {
+ jmsMessagingTemplate.convertAndSend("test", "hello world");
+ return SUCCESS;
+ }
+
+ @RequestMapping("/healthCheck")
+ @ResponseBody
+ public String healthCheck() {
+ return SUCCESS;
+ }
+
+ @JmsListener(destination = "test", concurrency = "10")
+ public void onMessageReceived(Message message) throws Exception {
+ TextMessage textMessage = (TextMessage) message;
+ log.info("received normal message: " + textMessage.getText());
+ }
+
+}
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/resources/application.yaml b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/resources/application.yaml
new file mode 100644
index 0000000000..189166b6a0
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/resources/application.yaml
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+#
+server:
+ port: 8080
+ servlet:
+ context-path: /spring-jms-5.x-scenario
+logging:
+ config: classpath:log4j2.xml
\ No newline at end of file
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/resources/log4j2.xml
new file mode 100644
index 0000000000..9849ed5a8a
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/src/main/resources/log4j2.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list b/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
new file mode 100644
index 0000000000..02e6b2f141
--- /dev/null
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
@@ -0,0 +1,18 @@
+# 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.
+
+# lists your version here (Contains only the last version number of each minor version.)
+5.3.37
\ No newline at end of file
From ccbffda47ad23f3e6394ff7d036369fbcc7b8262 Mon Sep 17 00:00:00 2001
From: hyhyf <627680933@qq.com>
Date: Sat, 20 Jul 2024 12:13:30 +0800
Subject: [PATCH 2/6] Update Spring-jms-5.x-plugin & Supported-list.md &
CHANGES.md
---
CHANGES.md | 2 +-
.../spring/jms/define/MessageListenerInstrumentation.java | 4 ++--
docs/en/setup/service-agent/java-agent/Supported-list.md | 2 +-
.../scenarios/spring-jms-5.x-scenario/support-version.list | 5 ++++-
4 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 5a04e0b1b7..91a4145f91 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -22,7 +22,7 @@ Release Notes.
* Improve 4x performance of ContextManagerExtendService.createTraceContext()
* Add a plugin that supports the Solon framework.
* Fixed issues in the MySQL component where the executeBatch method could result in empty SQL statements .
-* Add a plugin that supports the spring jms 5.x.
+* Add a plugin that supports the Spring JMS 5.x.
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/213?closed=1)
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/define/MessageListenerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/define/MessageListenerInstrumentation.java
index b8dfd3609b..4117dc09e1 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/define/MessageListenerInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/define/MessageListenerInstrumentation.java
@@ -24,9 +24,9 @@
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 static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
public class MessageListenerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
@@ -63,6 +63,6 @@ public boolean isOverrideArgs() {
@Override
protected ClassMatch enhanceClass() {
- return MultiClassNameMatch.byMultiClassMatch(ENHANCE_CLASS);
+ return byName(ENHANCE_CLASS);
}
}
diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md
index b21c8709b1..b5c1db5e3f 100644
--- a/docs/en/setup/service-agent/java-agent/Supported-list.md
+++ b/docs/en/setup/service-agent/java-agent/Supported-list.md
@@ -84,7 +84,7 @@ metrics based on the tracing data.
* [NATS](https://github.com/nats-io/nats.java) 2.14.x -> 2.15.x
* [ActiveMQ-Artemis](https://github.com/apache/activemq) 2.30.0 -> 2.31.2
* Aliyun ONS 1.x (Optional¹)
- * Spring Jms 5.x
+ * Spring JMS 5.x
* NoSQL
* [aerospike](https://github.com/aerospike/aerospike-client-java) 3.x -> 6.x
* Redis
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list b/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
index 02e6b2f141..fca6b63446 100644
--- a/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
@@ -15,4 +15,7 @@
# limitations under the License.
# lists your version here (Contains only the last version number of each minor version.)
-5.3.37
\ No newline at end of file
+5.3.37
+5.2.25.RELEASE
+5.1.20.RELEASE
+5.0.20.RELEASE
\ No newline at end of file
From 8beb20ae9af6c099d04c143709541d1013103144 Mon Sep 17 00:00:00 2001
From: hyhyf <627680933@qq.com>
Date: Sun, 21 Jul 2024 12:01:40 +0800
Subject: [PATCH 3/6] Update Spring-jms-5.x-scenario support-version.list
---
.../scenarios/spring-jms-5.x-scenario/support-version.list | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list b/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
index fca6b63446..0453772166 100644
--- a/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
@@ -17,5 +17,4 @@
# lists your version here (Contains only the last version number of each minor version.)
5.3.37
5.2.25.RELEASE
-5.1.20.RELEASE
-5.0.20.RELEASE
\ No newline at end of file
+5.1.20.RELEASE
\ No newline at end of file
From c2e3c75123a1fc41017c7bff52e6bf9c88652074 Mon Sep 17 00:00:00 2001
From: hyhyf <627680933@qq.com>
Date: Sun, 28 Jul 2024 15:39:06 +0800
Subject: [PATCH 4/6] Update Spring-jms-5.x-scenario pom.xml
---
test/plugin/scenarios/spring-jms-5.x-scenario/pom.xml | 11 ++++++++++-
.../spring-jms-5.x-scenario/support-version.list | 3 ++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/pom.xml b/test/plugin/scenarios/spring-jms-5.x-scenario/pom.xml
index b7214ee831..b657dd4b81 100644
--- a/test/plugin/scenarios/spring-jms-5.x-scenario/pom.xml
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/pom.xml
@@ -32,7 +32,7 @@
1.83.8.15.3.37
- 2.1.6.RELEASE
+ 2.0.9.RELEASE1.18.20
@@ -48,6 +48,10 @@
org.springframework.bootspring-boot-starter-logging
+
+ org.springframework
+ spring-context
+
@@ -72,6 +76,11 @@
+
+ org.springframework
+ spring-context
+ ${test.framework.version}
+ org.springframeworkspring-jms
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list b/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
index 0453772166..fca6b63446 100644
--- a/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/support-version.list
@@ -17,4 +17,5 @@
# lists your version here (Contains only the last version number of each minor version.)
5.3.37
5.2.25.RELEASE
-5.1.20.RELEASE
\ No newline at end of file
+5.1.20.RELEASE
+5.0.20.RELEASE
\ No newline at end of file
From c83d02c5b5493854e2108f240f021541b7c52746 Mon Sep 17 00:00:00 2001
From: hyhyf <627680933@qq.com>
Date: Tue, 30 Jul 2024 20:52:21 +0800
Subject: [PATCH 5/6] Update expectedData.yaml & messageListenerInterceptor
---
.../plugin/spring/jms/MessageListenerInterceptor.java | 9 ++++++---
.../spring-jms-5.x-scenario/config/expectedData.yaml | 9 ++-------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java
index deb6c4e7fe..2ca16139a4 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java
@@ -32,14 +32,17 @@
public class MessageListenerInterceptor implements InstanceMethodsAroundInterceptor {
- private static final String OPERATION_NAME_PREFIX = "Jms/";
- private static final String OPERATION_NAME_SUFFIX = "/Execute";
+ private static final String OPERATION_NAME_PREFIX = "JMS/";
+ private static final String OPERATION_NAME_SUFFIX = "/execute";
@Override
public void beforeMethod(EnhancedInstance objInst,
Method method,
Object[] allArguments, Class>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
+ if (allArguments[1] == null) {
+ return;
+ }
Message message = (Message) allArguments[1];
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
@@ -50,7 +53,7 @@ public void beforeMethod(EnhancedInstance objInst,
next.setHeadValue(propertyValue.toString());
}
}
- AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATION_NAME_PREFIX + message.getJMSDestination() + OPERATION_NAME_SUFFIX, null);
+ AbstractSpan activeSpan = ContextManager.createLocalSpan(OPERATION_NAME_PREFIX + message.getJMSDestination() + OPERATION_NAME_SUFFIX);
activeSpan.setComponent(ComponentsDefine.SPRING_ASYNC);
ContextManager.extract(contextCarrier);
}
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml
index ceecdfb29f..997483dfd7 100644
--- a/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml
@@ -71,7 +71,7 @@ segmentItems:
skipAnalysis: 'false'
- segmentId: not null
spans:
- - operationName: Jms/queue://test/Execute
+ - operationName: JMS/queue://test/execute
parentSpanId: -1
spanId: 0
spanLayer: Unknown
@@ -79,12 +79,7 @@ segmentItems:
endTime: nq 0
componentId: 65
isError: false
- spanType: Entry
+ spanType: Local
peer: ''
tags:
- { key: transmission.latency, value: ge 0 }
- refs:
- - { parentEndpoint: GET:/spring-jms-5.x-scenario/case/spring-jms-scenario, networkAddress: not null,
- refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null,
- parentServiceInstance: not null, parentService: not null, traceId: not null }
- skipAnalysis: 'false'
From 41c59ac66c2709c0a2a64a34f7cf5882bde36be7 Mon Sep 17 00:00:00 2001
From: hyhyf <627680933@qq.com>
Date: Thu, 1 Aug 2024 00:58:01 +0800
Subject: [PATCH 6/6] Update Spring JMS interceptor & expectedData.yaml &
configuration.yml
---
.../jms/MessageListenerInterceptor.java | 24 ++++----
.../config/expectedData.yaml | 57 +------------------
.../spring-jms-5.x-scenario/configuration.yml | 1 -
3 files changed, 14 insertions(+), 68 deletions(-)
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java
index 2ca16139a4..354b1e5793 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-jms-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/jms/MessageListenerInterceptor.java
@@ -18,9 +18,8 @@
package org.apache.skywalking.apm.plugin.spring.jms;
-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.ContextSnapshot;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
@@ -44,18 +43,19 @@ public void beforeMethod(EnhancedInstance objInst,
return;
}
Message message = (Message) allArguments[1];
- ContextCarrier contextCarrier = new ContextCarrier();
- CarrierItem next = contextCarrier.items();
- while (next.hasNext()) {
- next = next.next();
- Object propertyValue = message.getStringProperty(next.getHeadKey());
- if (propertyValue != null) {
- next.setHeadValue(propertyValue.toString());
+
+ AbstractSpan activeSpan = ContextManager.createLocalSpan(OPERATION_NAME_PREFIX
+ + message.getJMSDestination()
+ + OPERATION_NAME_SUFFIX);
+ activeSpan.setComponent(ComponentsDefine.SPRING_ASYNC);
+
+ if (EnhancedInstance.class.isAssignableFrom(allArguments[1].getClass())) {
+ EnhancedInstance messageInstance = (EnhancedInstance) allArguments[1];
+ ContextSnapshot snapshot = (ContextSnapshot) messageInstance.getSkyWalkingDynamicField();
+ if (null != snapshot) {
+ ContextManager.continued(snapshot);
}
}
- AbstractSpan activeSpan = ContextManager.createLocalSpan(OPERATION_NAME_PREFIX + message.getJMSDestination() + OPERATION_NAME_SUFFIX);
- activeSpan.setComponent(ComponentsDefine.SPRING_ASYNC);
- ContextManager.extract(contextCarrier);
}
@Override
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml
index 997483dfd7..01e790f9f0 100644
--- a/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/config/expectedData.yaml
@@ -15,60 +15,8 @@
# limitations under the License.
segmentItems:
- serviceName: spring-jms-5.x-scenario
- segmentSize: ge 2
+ segmentSize: ge 1
segments:
- - segmentId: not null
- spans:
- - operationName: ActiveMQ/Queue/test/Producer
- parentSpanId: 0
- spanId: 1
- spanLayer: MQ
- startTime: nq 0
- endTime: nq 0
- componentId: 45
- isError: false
- spanType: Exit
- peer: not blank
- tags:
- - { key: mq.broker, value: not blank }
- - { key: mq.queue, value: test }
- skipAnalysis: 'false'
- - operationName: GET:/spring-jms-5.x-scenario/case/spring-jms-scenario
- parentSpanId: -1
- spanId: 0
- spanLayer: Http
- startTime: nq 0
- endTime: nq 0
- componentId: 1
- isError: false
- spanType: Entry
- peer: ''
- tags:
- - { key: url, value: 'http://localhost:8080/spring-jms-5.x-scenario/case/spring-jms-scenario' }
- - { key: http.method, value: GET }
- - { key: http.status_code, value: '200' }
- skipAnalysis: 'false'
- - segmentId: not null
- spans:
- - operationName: ActiveMQ/Queue/test/Consumer
- parentSpanId: -1
- spanId: 0
- spanLayer: MQ
- startTime: nq 0
- endTime: nq 0
- componentId: 46
- isError: false
- spanType: Entry
- peer: not blank
- tags:
- - { key: mq.broker, value: not blank }
- - { key: mq.queue, value: test }
- - { key: transmission.latency, value: ge 0 }
- refs:
- - { parentEndpoint: GET:/spring-jms-5.x-scenario/case/spring-jms-scenario, networkAddress: not null,
- refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null,
- parentServiceInstance: not null, parentService: not null, traceId: not null }
- skipAnalysis: 'false'
- segmentId: not null
spans:
- operationName: JMS/queue://test/execute
@@ -81,5 +29,4 @@ segmentItems:
isError: false
spanType: Local
peer: ''
- tags:
- - { key: transmission.latency, value: ge 0 }
+ skipAnalysis: 'false'
diff --git a/test/plugin/scenarios/spring-jms-5.x-scenario/configuration.yml b/test/plugin/scenarios/spring-jms-5.x-scenario/configuration.yml
index f19d35f3e9..0a795f106e 100644
--- a/test/plugin/scenarios/spring-jms-5.x-scenario/configuration.yml
+++ b/test/plugin/scenarios/spring-jms-5.x-scenario/configuration.yml
@@ -17,7 +17,6 @@
type: jvm
entryService: http://localhost:8080/spring-jms-5.x-scenario/case/spring-jms-scenario
healthCheck: http://localhost:8080/spring-jms-5.x-scenario/case/healthCheck
-withPlugins: apm-activemq-5.x-plugin-*.jar
startScript: ./bin/startup.sh
environment:
- activemq.server=tcp://activemq-server:61616