From 9a9401fdb69639ac2fff67bbdc6ad8d581ba418e Mon Sep 17 00:00:00 2001
From: xiaoyu <549477611@qq.com>
Date: Thu, 11 Jun 2020 14:49:04 +0800
Subject: [PATCH] provide shardingSphere(4.0.0,4.0.1, 4.1.0 ,4.1.1) plugin.
(#4894)
---
CHANGES.md | 1 +
apm-sniffer/apm-sdk-plugin/pom.xml | 1 +
.../sharding-sphere-4.1.0-plugin/pom.xml | 60 ++++++
.../plugin/shardingsphere/v41/Constant.java | 30 +++
.../v41/ExecuteInterceptor.java | 65 +++++++
.../v41/JDBCRootInvokeInterceptor.java | 55 ++++++
.../shardingsphere/v41/ParseInterceptor.java | 56 ++++++
.../v41/ProxyRootInvokeInterceptor.java | 55 ++++++
.../v41/define/ExecuteInstrumentation.java | 71 +++++++
.../define/JDBCRootInvokeInstrumentation.java | 71 +++++++
.../v41/define/ParseInstrumentation.java | 71 +++++++
.../ProxyRootInvokeInstrumentation.java | 71 +++++++
.../v41/threadlocal/ContextThreadLocal.java | 48 +++++
.../src/main/resources/skywalking-plugin.def | 19 ++
.../shardingsphere/InterceptorTest.java | 129 +++++++++++++
.../java-agent/Supported-list.md | 2 +-
.../bin/startup.sh | 21 +++
.../config/expectedData.yaml | 174 ++++++++++++++++++
.../configuration.yml | 20 ++
.../shardingsphere-4.x-scenario/pom.xml | 153 +++++++++++++++
.../src/main/assembly/assembly.xml | 41 +++++
.../testcase/shardingsphere/Application.java | 50 +++++
.../controller/CaseController.java | 49 +++++
.../service/api/entity/Order.java | 61 ++++++
.../service/api/entity/OrderItem.java | 71 +++++++
.../api/repository/CommonRepository.java | 38 ++++
.../api/repository/OrderItemRepository.java | 24 +++
.../api/repository/OrderRepository.java | 24 +++
.../service/api/service/CommonService.java | 32 ++++
.../api/service/CommonServiceImpl.java | 108 +++++++++++
...atabasesAndTablesConfigurationPrecise.java | 75 ++++++++
.../jdbc/JDBCOrderItemRepositoryImpl.java | 123 +++++++++++++
.../jdbc/JDBCOrderRepositoryImpl.java | 121 ++++++++++++
.../repository/service/RawPojoService.java | 60 ++++++
...reciseModuloShardingDatabaseAlgorithm.java | 37 ++++
.../PreciseModuloShardingTableAlgorithm.java | 36 ++++
.../RangeModuloShardingDatabaseAlgorithm.java | 53 ++++++
.../RangeModuloShardingTableAlgorithm.java | 45 +++++
.../utility/config/DataSourceUtil.java | 55 ++++++
.../utility/config/ExampleConfiguration.java | 29 +++
.../src/main/resources/application.properties | 17 ++
.../support-version.list | 20 ++
42 files changed, 2341 insertions(+), 1 deletion(-)
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/pom.xml
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/Constant.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ExecuteInterceptor.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/JDBCRootInvokeInterceptor.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ParseInterceptor.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ProxyRootInvokeInterceptor.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ExecuteInstrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/JDBCRootInvokeInstrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ParseInstrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ProxyRootInvokeInstrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/threadlocal/ContextThreadLocal.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/resources/skywalking-plugin.def
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/test/java/org/apache/skywalking/apm/plugin/shardingsphere/InterceptorTest.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/bin/startup.sh
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/config/expectedData.yaml
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/configuration.yml
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/pom.xml
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/assembly/assembly.xml
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/Application.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/controller/CaseController.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/Order.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/OrderItem.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/CommonRepository.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderItemRepository.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderRepository.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonService.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonServiceImpl.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/config/ShardingDatabasesAndTablesConfigurationPrecise.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderItemRepositoryImpl.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderRepositoryImpl.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/service/RawPojoService.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingDatabaseAlgorithm.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingTableAlgorithm.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingDatabaseAlgorithm.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingTableAlgorithm.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/DataSourceUtil.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/ExampleConfiguration.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/src/main/resources/application.properties
create mode 100644 test/plugin/scenarios/shardingsphere-4.x-scenario/support-version.list
diff --git a/CHANGES.md b/CHANGES.md
index bd2519751..70d73560c 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -12,6 +12,7 @@ Release Notes.
* Support Prometheus network protocol. Metrics in Prometheus format could be transferred into SkyWalking.
* Python agent provided.
* All inventory caches have been removed.
+* Apache ShardingSphere(4.0.0, 4.1.1) agent plugin provided.
#### Java Agent
* Add MariaDB plugin.
diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml
index 1c9d9d249..8c88299bc 100644
--- a/apm-sniffer/apm-sdk-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/pom.xml
@@ -47,6 +47,7 @@
sharding-sphere-3.x-pluginsharding-sphere-4.x-pluginsharding-sphere-4.x-RC3-plugin
+ sharding-sphere-4.1.0-pluginxmemcached-2.x-plugingrpc-1.x-pluginmysql-5.x-plugin
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/pom.xml
new file mode 100644
index 000000000..41055592b
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/pom.xml
@@ -0,0 +1,60 @@
+
+
+
+
+ apm-sdk-plugin
+ org.apache.skywalking
+ 8.0.0-SNAPSHOT
+
+ 4.0.0
+
+ apm-sharding-sphere-4.1.0-plugin
+
+ jar
+ sharding-sphere-4.1.0-plugin
+ http://maven.apache.org
+
+
+ UTF-8
+ [4.0.0,4.1.1]
+
+
+
+
+ mysql
+ mysql-connector-java
+ [2.0.14,6.0.6]
+ test
+
+
+ org.apache.shardingsphere
+ sharding-core-execute
+ ${shardingsphere.version}
+ provided
+
+
+ org.apache.shardingsphere
+ sharding-jdbc-core
+ ${shardingsphere.version}
+ provided
+
+
+
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/Constant.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/Constant.java
new file mode 100644
index 000000000..e573126eb
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/Constant.java
@@ -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.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.shardingsphere.v41;
+
+/**
+ * The type Constant.
+ */
+public final class Constant {
+
+ /**
+ * The constant CONTEXT_SNAPSHOT.
+ */
+ public static final String CONTEXT_SNAPSHOT = "CONTEXT_SNAPSHOT";
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ExecuteInterceptor.java
new file mode 100644
index 000000000..3381446ae
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ExecuteInterceptor.java
@@ -0,0 +1,65 @@
+/*
+ * 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.shardingsphere.v41;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+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.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 org.apache.skywalking.apm.plugin.shardingsphere.v41.threadlocal.ContextThreadLocal;
+
+/**
+ * {@link ExecuteInterceptor} enhances. {@link org.apache.shardingsphere.sharding.execute.sql.execute.SQLExecuteCallback}
+ * creating a local span that records the execution of sql.
+ */
+public class ExecuteInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ MethodInterceptResult result) {
+ ContextManager.createLocalSpan("/ShardingSphere/executeSQL/").setComponent(ComponentsDefine.SHARDING_SPHERE);
+ ContextSnapshot contextSnapshot = (ContextSnapshot) ContextThreadLocal.getValue()
+ .get(Constant.CONTEXT_SNAPSHOT);
+ if (null == contextSnapshot) {
+ contextSnapshot = (ContextSnapshot) ((Map) allArguments[2]).get(Constant.CONTEXT_SNAPSHOT);
+ }
+ if (null != contextSnapshot) {
+ ContextManager.continued(contextSnapshot);
+ }
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ Object ret) {
+ ContextManager.stopSpan();
+ ContextThreadLocal.remove();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().errorOccurred().log(t);
+ ContextThreadLocal.remove();
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/JDBCRootInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/JDBCRootInvokeInterceptor.java
new file mode 100644
index 000000000..b7ed611f7
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/JDBCRootInvokeInterceptor.java
@@ -0,0 +1,55 @@
+/*
+ * 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.shardingsphere.v41;
+
+import java.lang.reflect.Method;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+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 org.apache.skywalking.apm.plugin.shardingsphere.v41.threadlocal.ContextThreadLocal;
+
+/**
+ * {@link JDBCRootInvokeInterceptor} enhances {@link org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor},
+ * creating a local span that records the overall execution of sql.
+ */
+public class JDBCRootInvokeInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ MethodInterceptResult result) {
+ ContextManager.createLocalSpan("/ShardingSphere/JDBCRootInvoke/")
+ .setComponent(ComponentsDefine.SHARDING_SPHERE);
+ ContextThreadLocal.getValue().put(Constant.CONTEXT_SNAPSHOT, ContextManager.capture());
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ Object ret) {
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().errorOccurred().log(t);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ParseInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ParseInterceptor.java
new file mode 100644
index 000000000..875f6bbaf
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ParseInterceptor.java
@@ -0,0 +1,56 @@
+/*
+ * 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.shardingsphere.v41;
+
+import java.lang.reflect.Method;
+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.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;
+
+/**
+ * {@link ParseInterceptor} enhances {@link org.apache.shardingsphere.sql.parser.SQLParserEngine}.
+ * creating a local span that records the parse of sql.
+ */
+public class ParseInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ MethodInterceptResult result) {
+ AbstractSpan span = ContextManager.createLocalSpan("/ShardingSphere/parseSQL/")
+ .setComponent(ComponentsDefine.SHARDING_SPHERE);
+ Tags.DB_STATEMENT.set(span, (String) allArguments[0]);
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ Object ret) {
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().errorOccurred().log(t);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ProxyRootInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ProxyRootInvokeInterceptor.java
new file mode 100644
index 000000000..2dc29fdf2
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ProxyRootInvokeInterceptor.java
@@ -0,0 +1,55 @@
+/*
+ * 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.shardingsphere.v41;
+
+import java.lang.reflect.Method;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+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 org.apache.skywalking.apm.plugin.shardingsphere.v41.threadlocal.ContextThreadLocal;
+
+/**
+ * ProxyRootInvokeInterceptor enhances. skywalking intercepts org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask
+ * creating a local span that records the overall execution of sql.
+ */
+public class ProxyRootInvokeInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ MethodInterceptResult result) {
+ ContextManager.createLocalSpan("/ShardingSphere/ProxyRootInvoke/")
+ .setComponent(ComponentsDefine.SHARDING_SPHERE);
+ ContextThreadLocal.getValue().put(Constant.CONTEXT_SNAPSHOT, ContextManager.capture());
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ Object ret) {
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().errorOccurred().log(t);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ExecuteInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ExecuteInstrumentation.java
new file mode 100644
index 000000000..61f3990ff
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ExecuteInstrumentation.java
@@ -0,0 +1,71 @@
+/*
+ * 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.shardingsphere.v41.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.NameMatch;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+
+/**
+ * {@link ExecuteInstrumentation} presents that skywalking intercepts. {@link org.apache.shardingsphere.sharding.execute.sql.execute.SQLExecuteCallback}.
+ */
+public class ExecuteInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+
+ private static final String ENHANCE_CLASS = "org.apache.shardingsphere.sharding.execute.sql.execute.SQLExecuteCallback";
+
+ private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v41.ExecuteInterceptor";
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named("execute0");
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return EXECUTE_INTERCEPTOR_CLASS;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[0];
+ }
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return NameMatch.byName(ENHANCE_CLASS);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/JDBCRootInvokeInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/JDBCRootInvokeInstrumentation.java
new file mode 100644
index 000000000..6305e0aed
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/JDBCRootInvokeInstrumentation.java
@@ -0,0 +1,71 @@
+/*
+ * 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.shardingsphere.v41.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.NameMatch;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+
+/**
+ * {@link JDBCRootInvokeInstrumentation} presents that skywalking intercepts. {@link org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor}.
+ */
+public class JDBCRootInvokeInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+
+ private static final String ENHANCE_CLASS = "org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor";
+
+ private static final String JDBC_ROOT_INVOKE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v41.JDBCRootInvokeInterceptor";
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named("executeCallback");
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return JDBC_ROOT_INVOKE_INTERCEPTOR_CLASS;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[0];
+ }
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return NameMatch.byName(ENHANCE_CLASS);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ParseInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ParseInstrumentation.java
new file mode 100644
index 000000000..9161f0d68
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ParseInstrumentation.java
@@ -0,0 +1,71 @@
+/*
+ * 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.shardingsphere.v41.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.NameMatch;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+
+/**
+ * {@link ParseInstrumentation} presents that skywalking intercepts {@link org.apache.shardingsphere.sql.parser.SQLParserEngine}.
+ */
+public class ParseInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+
+ private static final String ENHANCE_CLASS = "org.apache.shardingsphere.sql.parser.SQLParserEngine";
+
+ private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v41.ParseInterceptor";
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named("parse");
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return EXECUTE_INTERCEPTOR_CLASS;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[0];
+ }
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return NameMatch.byName(ENHANCE_CLASS);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ProxyRootInvokeInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ProxyRootInvokeInstrumentation.java
new file mode 100644
index 000000000..6aa51ae55
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ProxyRootInvokeInstrumentation.java
@@ -0,0 +1,71 @@
+/*
+ * 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.shardingsphere.v41.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.NameMatch;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+
+/**
+ * ProxyRootInvokeInstrumentation presents that skywalking intercepts. skywalking intercepts org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.
+ */
+public class ProxyRootInvokeInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+
+ private static final String ENHANCE_CLASS = "org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask";
+
+ private static final String PROXY_ROOT_INVOKE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v41.ProxyRootInvokeInterceptor";
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named("run");
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return PROXY_ROOT_INVOKE_INTERCEPTOR_CLASS;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[0];
+ }
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return NameMatch.byName(ENHANCE_CLASS);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/threadlocal/ContextThreadLocal.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/threadlocal/ContextThreadLocal.java
new file mode 100644
index 000000000..12e4e1db6
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/threadlocal/ContextThreadLocal.java
@@ -0,0 +1,48 @@
+/*
+ * 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.shardingsphere.v41.threadlocal;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Context thread local for skywalking.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ContextThreadLocal {
+
+ private static ThreadLocal