From 164124fc22721c7ea99b35aa1a2f237eedb795ac Mon Sep 17 00:00:00 2001
From: xiaoyu <549477611@qq.com>
Date: Mon, 15 Jun 2020 17:03:17 +0800
Subject: [PATCH] provider shardingSphere 4.0.0 4.0.1 plugin. (#4927)
---
.github/workflows/plugins-test.2.yaml | 1 +
apm-sniffer/apm-sdk-plugin/pom.xml | 1 +
.../sharding-sphere-4.0.x-plugin/pom.xml | 67 +++++++
.../plugin/shardingsphere/v40/Constant.java | 30 +++
.../v40/ExecuteInterceptor.java | 64 +++++++
.../v40/JDBCRootInvokeInterceptor.java | 56 ++++++
.../shardingsphere/v40/ParseInterceptor.java | 57 ++++++
.../v40/ProxyRootInvokeInterceptor.java | 56 ++++++
...stractShardingSphere40Instrumentation.java | 29 +++
.../v40/define/ExecuteInstrumentation.java | 70 +++++++
.../define/JDBCRootInvokeInstrumentation.java | 70 +++++++
.../v40/define/ParseInstrumentation.java | 70 +++++++
.../ProxyRootInvokeInstrumentation.java | 70 +++++++
.../src/main/resources/skywalking-plugin.def | 19 ++
.../shardingsphere/InterceptorTest.java | 130 +++++++++++++
...ractShardingSphereV4R3Instrumentation.java | 2 +-
.../v4rc3/define/ParseInstrumentation.java | 3 +-
.../java-agent/Supported-list.md | 2 +-
.../bin/startup.sh | 21 +++
.../config/expectedData.yaml | 174 ++++++++++++++++++
.../configuration.yml | 20 ++
.../shardingsphere-4.0.x-scenario/pom.xml | 154 ++++++++++++++++
.../src/main/assembly/assembly.xml | 41 +++++
.../testcase/shardingsphere/Application.java | 51 +++++
.../controller/CaseController.java | 50 +++++
.../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 | 109 +++++++++++
...atabasesAndTablesConfigurationPrecise.java | 76 ++++++++
.../jdbc/JDBCOrderItemRepositoryImpl.java | 120 ++++++++++++
.../jdbc/JDBCOrderRepositoryImpl.java | 118 ++++++++++++
.../repository/service/RawPojoService.java | 60 ++++++
...reciseModuloShardingDatabaseAlgorithm.java | 38 ++++
.../PreciseModuloShardingTableAlgorithm.java | 37 ++++
.../RangeModuloShardingDatabaseAlgorithm.java | 54 ++++++
.../RangeModuloShardingTableAlgorithm.java | 46 +++++
.../utility/config/DataSourceUtil.java | 56 ++++++
.../utility/config/ExampleConfiguration.java | 29 +++
.../src/main/resources/application.properties | 17 ++
.../support-version.list | 18 ++
44 files changed, 2332 insertions(+), 4 deletions(-)
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/pom.xml
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/Constant.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ExecuteInterceptor.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/JDBCRootInvokeInterceptor.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ParseInterceptor.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ProxyRootInvokeInterceptor.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/AbstractShardingSphere40Instrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ExecuteInstrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/JDBCRootInvokeInstrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ParseInstrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ProxyRootInvokeInstrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/resources/skywalking-plugin.def
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/shardingsphere/InterceptorTest.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/bin/startup.sh
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/config/expectedData.yaml
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/configuration.yml
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/pom.xml
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/assembly/assembly.xml
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/Application.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/controller/CaseController.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/Order.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/OrderItem.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/CommonRepository.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderItemRepository.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderRepository.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonService.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonServiceImpl.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/config/ShardingDatabasesAndTablesConfigurationPrecise.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderItemRepositoryImpl.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderRepositoryImpl.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/service/RawPojoService.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingDatabaseAlgorithm.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingTableAlgorithm.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingDatabaseAlgorithm.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingTableAlgorithm.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/DataSourceUtil.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/ExampleConfiguration.java
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/resources/application.properties
create mode 100644 test/plugin/scenarios/shardingsphere-4.0.x-scenario/support-version.list
diff --git a/.github/workflows/plugins-test.2.yaml b/.github/workflows/plugins-test.2.yaml
index 75a0a30dd..fd1ef987e 100644
--- a/.github/workflows/plugins-test.2.yaml
+++ b/.github/workflows/plugins-test.2.yaml
@@ -45,6 +45,7 @@ jobs:
- { name: 'shardingsphere-3.x-scenario', title: 'ShardingSphere 3.0.0 (1)' }
- { name: 'shardingsphere-4.x-RC1-RC2-scenario', title: 'ShardingSphere 4.0.0-RC1-4.0.0-RC2 (2)' }
- { name: 'shardingsphere-4.x-RC3-scenario', title: 'ShardingSphere 4.0.0-RC3 (1)' }
+ - { name: 'shardingsphere-4.0.x-scenario', title: 'ShardingSphere 4.0.0-4.0.1 (2)' }
- { name: 'shardingsphere-4.x-scenario', title: 'ShardingSphere 4.1.0-4.1.1 (2)' }
- { name: 'sofarpc-scenario', title: 'SofaRPC 5.4.0-5.6.2 (23)' }
- { name: 'solrj-7.x-scenario', title: 'SolrJ 7.x (12)' }
diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml
index 75c317bdc..4520b78a9 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.0.x-pluginsharding-sphere-4.1.0-pluginxmemcached-2.x-plugingrpc-1.x-plugin
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/pom.xml
new file mode 100644
index 000000000..266e8432c
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/pom.xml
@@ -0,0 +1,67 @@
+
+
+
+
+ apm-sdk-plugin
+ org.apache.skywalking
+ 8.1.0-SNAPSHOT
+
+ 4.0.0
+
+ apm-shardingsphere-4.0.x-plugin
+
+
+ jar
+ sharding-sphere-4.0.x-plugin
+ http://maven.apache.org
+
+
+ UTF-8
+ 4.0.0
+
+
+
+
+ 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
+
+
+ org.apache.shardingsphere
+ shardingsphere-sql-parser-engine
+ ${shardingsphere.version}
+ provided
+
+
+
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/Constant.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/Constant.java
new file mode 100644
index 000000000..755c3bb3f
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/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.v40;
+
+/**
+ * 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.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ExecuteInterceptor.java
new file mode 100644
index 000000000..45281832c
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ExecuteInterceptor.java
@@ -0,0 +1,64 @@
+/*
+ * 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.v40;
+
+import org.apache.shardingsphere.core.execute.engine.ShardingExecuteDataMap;
+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 java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * {@link ExecuteInterceptor} enhances. {@link org.apache.shardingsphere.core.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) ShardingExecuteDataMap.getDataMap()
+ .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();
+ 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.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/JDBCRootInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/JDBCRootInvokeInterceptor.java
new file mode 100644
index 000000000..fad49e377
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/JDBCRootInvokeInterceptor.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.v40;
+
+import org.apache.shardingsphere.core.execute.engine.ShardingExecuteDataMap;
+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 java.lang.reflect.Method;
+
+/**
+ * {@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);
+ ShardingExecuteDataMap.getDataMap().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.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ParseInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ParseInterceptor.java
new file mode 100644
index 000000000..9859f50da
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ParseInterceptor.java
@@ -0,0 +1,57 @@
+/*
+ * 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.v40;
+
+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;
+
+import java.lang.reflect.Method;
+
+/**
+ * {@link ParseInterceptor} enhances {@link org.apache.shardingsphere.core.route.router.sharding.ShardingRouter}.
+ * 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.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ProxyRootInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ProxyRootInvokeInterceptor.java
new file mode 100644
index 000000000..4f416f6fb
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ProxyRootInvokeInterceptor.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.v40;
+
+import org.apache.shardingsphere.core.execute.engine.ShardingExecuteDataMap;
+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 java.lang.reflect.Method;
+
+/**
+ * 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);
+ ShardingExecuteDataMap.getDataMap().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.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/AbstractShardingSphere40Instrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/AbstractShardingSphere40Instrumentation.java
new file mode 100644
index 000000000..9afe2be20
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/AbstractShardingSphere40Instrumentation.java
@@ -0,0 +1,29 @@
+/*
+ * 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.v40.define;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+
+public abstract class AbstractShardingSphere40Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+ public static final String WITHNESS_CLASSES = "org.apache.shardingsphere.sql.parser.SQLParseEngine";
+
+ @Override
+ protected final String[] witnessClasses() {
+ return new String[] {WITHNESS_CLASSES};
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ExecuteInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ExecuteInstrumentation.java
new file mode 100644
index 000000000..7a2f70f0e
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ExecuteInstrumentation.java
@@ -0,0 +1,70 @@
+/*
+ * 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.v40.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.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.core.execute.sql.execute.SQLExecuteCallback}.
+ */
+public class ExecuteInstrumentation extends AbstractShardingSphere40Instrumentation {
+
+ private static final String ENHANCE_CLASS = "org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback";
+
+ private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v40.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.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/JDBCRootInvokeInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/JDBCRootInvokeInstrumentation.java
new file mode 100644
index 000000000..e01fd8e24
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/JDBCRootInvokeInstrumentation.java
@@ -0,0 +1,70 @@
+/*
+ * 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.v40.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.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 AbstractShardingSphere40Instrumentation {
+
+ 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.v40.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.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ParseInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ParseInstrumentation.java
new file mode 100644
index 000000000..0c5c386c8
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ParseInstrumentation.java
@@ -0,0 +1,70 @@
+/*
+ * 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.v40.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.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.core.route.router.sharding.ShardingRouter}.
+ */
+public class ParseInstrumentation extends AbstractShardingSphere40Instrumentation {
+
+ private static final String ENHANCE_CLASS = "org.apache.shardingsphere.core.route.router.sharding.ShardingRouter";
+
+ private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v40.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.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ProxyRootInvokeInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ProxyRootInvokeInstrumentation.java
new file mode 100644
index 000000000..7b787565a
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ProxyRootInvokeInstrumentation.java
@@ -0,0 +1,70 @@
+/*
+ * 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.v40.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.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 AbstractShardingSphere40Instrumentation {
+
+ 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.v40.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.0.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/resources/skywalking-plugin.def
new file mode 100644
index 000000000..636580a94
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/resources/skywalking-plugin.def
@@ -0,0 +1,19 @@
+# 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.
+sharding-sphere-4.0.0=org.apache.skywalking.apm.plugin.shardingsphere.v40.define.ProxyRootInvokeInstrumentation
+sharding-sphere-4.0.0=org.apache.skywalking.apm.plugin.shardingsphere.v40.define.JDBCRootInvokeInstrumentation
+sharding-sphere-4.0.0=org.apache.skywalking.apm.plugin.shardingsphere.v40.define.ParseInstrumentation
+sharding-sphere-4.0.0=org.apache.skywalking.apm.plugin.shardingsphere.v40.define.ExecuteInstrumentation
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/shardingsphere/InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/shardingsphere/InterceptorTest.java
new file mode 100644
index 000000000..cb315e53e
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/shardingsphere/InterceptorTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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;
+
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
+import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
+import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
+import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
+import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
+import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
+import org.apache.skywalking.apm.agent.test.tools.SpanAssert;
+import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
+import org.apache.skywalking.apm.plugin.shardingsphere.v40.ExecuteInterceptor;
+import org.apache.skywalking.apm.plugin.shardingsphere.v40.JDBCRootInvokeInterceptor;
+import org.apache.skywalking.apm.plugin.shardingsphere.v40.ParseInterceptor;
+import org.apache.skywalking.apm.plugin.shardingsphere.v40.ProxyRootInvokeInterceptor;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+
+import java.util.HashMap;
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+public class InterceptorTest {
+
+ @SegmentStoragePoint
+ private SegmentStorage segmentStorage;
+
+ @Rule
+ public AgentServiceRule serviceRule = new AgentServiceRule();
+
+ private ProxyRootInvokeInterceptor proxyRootInvokeInterceptor;
+
+ private JDBCRootInvokeInterceptor jdbcRootInvokeInterceptor;
+
+ private ParseInterceptor parseInterceptor;
+
+ private ExecuteInterceptor executeInterceptor;
+
+ @Before
+ public void setUp() {
+ proxyRootInvokeInterceptor = new ProxyRootInvokeInterceptor();
+ jdbcRootInvokeInterceptor = new JDBCRootInvokeInterceptor();
+ parseInterceptor = new ParseInterceptor();
+ executeInterceptor = new ExecuteInterceptor();
+ }
+
+ @Test
+ public void assertProxyRootInvoke() {
+ proxyRootInvokeInterceptor.beforeMethod(null, null, null, null, null);
+ proxyRootInvokeInterceptor.afterMethod(null, null, null, null, null);
+ assertThat(segmentStorage.getTraceSegments().size(), is(1));
+ TraceSegment segment = segmentStorage.getTraceSegments().get(0);
+ List spans = SegmentHelper.getSpans(segment);
+ assertNotNull(spans);
+ assertThat(spans.size(), is(1));
+ assertThat(spans.get(0).getOperationName(), is("/ShardingSphere/ProxyRootInvoke/"));
+ }
+
+ @Test
+ public void assertJDBCRootInvoke() {
+ jdbcRootInvokeInterceptor.beforeMethod(null, null, null, null, null);
+ jdbcRootInvokeInterceptor.afterMethod(null, null, null, null, null);
+ assertThat(segmentStorage.getTraceSegments().size(), is(1));
+ TraceSegment segment = segmentStorage.getTraceSegments().get(0);
+ List spans = SegmentHelper.getSpans(segment);
+ assertNotNull(spans);
+ assertThat(spans.size(), is(1));
+ assertThat(spans.get(0).getOperationName(), is("/ShardingSphere/JDBCRootInvoke/"));
+ }
+
+ @Test
+ public void assertParse() {
+ Object[] allArguments = new Object[] {
+ "SELECT * FROM t_order",
+ false
+ };
+ parseInterceptor.beforeMethod(null, null, allArguments, null, null);
+ parseInterceptor.afterMethod(null, null, allArguments, null, null);
+ assertThat(segmentStorage.getTraceSegments().size(), is(1));
+ TraceSegment segment = segmentStorage.getTraceSegments().get(0);
+ List spans = SegmentHelper.getSpans(segment);
+ assertNotNull(spans);
+ assertThat(spans.size(), is(1));
+ assertThat(spans.get(0).getOperationName(), is("/ShardingSphere/parseSQL/"));
+ SpanAssert.assertTag(spans.get(0), 0, "SELECT * FROM t_order");
+ }
+
+ @Test
+ public void assertExecute() {
+ Object[] allArguments = new Object[] {
+ null,
+ null,
+ new HashMap