This is an automated email from the ASF dual-hosted git repository.

jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new f715ca373d1 Move the judgment of whether to enable the plugin to each 
advice. (#29754)
f715ca373d1 is described below

commit f715ca373d11a2897b08e21ed97cb063babd9860
Author: jiangML <[email protected]>
AuthorDate: Thu Jan 18 17:14:28 2024 +0800

    Move the judgment of whether to enable the plugin to each advice. (#29754)
    
    * Move the judgment of whether to enable the plugin to each advice.
    
    * Improve agent plugins
    
    * Update doc of AgentPluginEnable
    
    * Update doc of AgentPluginEnable
    
    * Update doc of AgentPluginEnable
    
    * Update doc of AgentPluginEnable
    
    * Update doc of AgentPluginEnable
    
    * Refactor AgentPluginEnable
---
 .../agent/api/plugin/AgentPluginEnable.java}       | 24 ++++-----
 agent/core/pom.xml                                 | 13 -----
 .../agent/core/ShardingSphereAgent.java            |  2 -
 .../executor/type/ConstructorAdviceExecutor.java   | 14 ++---
 .../type/InstanceMethodAdviceExecutor.java         | 32 ++++++------
 .../executor/type/StaticMethodAdviceExecutor.java  | 31 ++++++-----
 .../agent/core/plugin/PluginContextTest.java       | 61 ----------------------
 .../core/advice/AbstractInstanceMethodAdvice.java} | 20 +++----
 .../core/advice/AbstractStaticMethodAdvice.java}   | 20 +++----
 .../agent/plugin/core/context}/PluginContext.java  | 30 ++++++-----
 .../file/FileLoggingPluginLifecycleService.java    |  2 +
 .../file/advice/MetaDataContextsFactoryAdvice.java |  4 +-
 .../core/advice/RouteResultCountAdvice.java        |  4 +-
 .../metrics/core/advice/SQLParseCountAdvice.java   |  4 +-
 .../metrics/core/advice/SQLRouteCountAdvice.java   |  4 +-
 .../advice/jdbc/AbstractExecuteCountAdvice.java    |  4 +-
 .../jdbc/AbstractExecuteErrorsCountAdvice.java     |  4 +-
 .../AbstractExecuteLatencyHistogramAdvice.java     |  4 +-
 .../jdbc/AbstractTransactionsCountAdvice.java      |  4 +-
 .../proxy/CommitTransactionsCountAdvice.java       |  4 +-
 .../proxy/CurrentConnectionsCountAdvice.java       |  4 +-
 .../advice/proxy/ExecuteErrorsCountAdvice.java     |  4 +-
 .../proxy/ExecuteLatencyHistogramAdvice.java       |  4 +-
 .../core/advice/proxy/RequestsCountAdvice.java     |  4 +-
 .../proxy/RollbackTransactionsCountAdvice.java     |  4 +-
 .../PrometheusPluginLifecycleService.java          |  2 +
 agent/plugins/pom.xml                              | 25 +++++++++
 .../advice/TracingJDBCExecutorCallbackAdvice.java  |  4 +-
 .../tracing/core/advice/TracingRootSpanAdvice.java |  4 +-
 .../core/advice/TracingSQLParserEngineAdvice.java  |  4 +-
 ...OpenTelemetryTracingPluginLifecycleService.java |  2 +
 31 files changed, 147 insertions(+), 199 deletions(-)

diff --git 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
 
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/plugin/AgentPluginEnable.java
similarity index 61%
copy from 
agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
copy to 
agent/api/src/main/java/org/apache/shardingsphere/agent/api/plugin/AgentPluginEnable.java
index 2b1f2518187..8c790ab9b0e 100644
--- 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
+++ 
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/plugin/AgentPluginEnable.java
@@ -15,22 +15,16 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.agent.plugin.logging.file;
+package org.apache.shardingsphere.agent.api.plugin;
 
-import org.apache.shardingsphere.agent.api.PluginConfiguration;
-import org.apache.shardingsphere.agent.spi.PluginLifecycleService;
-
-/**
- * File logging plugin lifecycle service.
- */
-public final class FileLoggingPluginLifecycleService implements 
PluginLifecycleService {
-    
-    @Override
-    public void start(final PluginConfiguration pluginConfig, final boolean 
isEnhancedForProxy) {
-    }
+public interface AgentPluginEnable {
     
-    @Override
-    public String getType() {
-        return "File";
+    /**
+     * Is the plugin enabled.
+     *
+     * @return true or false
+     */
+    default boolean isPluginEnabled() {
+        return true;
     }
 }
diff --git a/agent/core/pom.xml b/agent/core/pom.xml
index d68e221e96d..ae4eb7db20f 100644
--- a/agent/core/pom.xml
+++ b/agent/core/pom.xml
@@ -36,19 +36,6 @@
             <artifactId>shardingsphere-agent-api</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-proxy-backend-core</artifactId>
-            <version>${project.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-jdbc-core</artifactId>
-            <version>${project.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        
         <dependency>
             <groupId>net.bytebuddy</groupId>
             <artifactId>byte-buddy</artifactId>
diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
index 90941a05649..a9537697935 100644
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
+++ 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
@@ -25,7 +25,6 @@ import 
org.apache.shardingsphere.agent.core.advisor.config.AdvisorConfiguration;
 import 
org.apache.shardingsphere.agent.core.advisor.config.AdvisorConfigurationLoader;
 import org.apache.shardingsphere.agent.core.builder.AgentBuilderFactory;
 import org.apache.shardingsphere.agent.core.path.AgentPath;
-import org.apache.shardingsphere.agent.core.plugin.PluginContext;
 import 
org.apache.shardingsphere.agent.core.plugin.config.PluginConfigurationLoader;
 import org.apache.shardingsphere.agent.core.plugin.jar.PluginJarLoader;
 
@@ -54,7 +53,6 @@ public final class ShardingSphereAgent {
         Map<String, PluginConfiguration> pluginConfigs = 
PluginConfigurationLoader.load(rootPath);
         Collection<JarFile> pluginJars = PluginJarLoader.load(rootPath);
         boolean isEnhancedForProxy = isEnhancedForProxy();
-        PluginContext.getInstance().setEnhancedForProxy(isEnhancedForProxy);
         Map<String, AdvisorConfiguration> advisorConfigs = 
AdvisorConfigurationLoader.load(pluginJars, pluginConfigs.keySet());
         AgentBuilderFactory.create(pluginConfigs, pluginJars, advisorConfigs, 
isEnhancedForProxy).installOn(instrumentation);
     }
diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/ConstructorAdviceExecutor.java
 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/ConstructorAdviceExecutor.java
index ddfe7e65321..3ebc0c50902 100644
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/ConstructorAdviceExecutor.java
+++ 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/ConstructorAdviceExecutor.java
@@ -28,8 +28,8 @@ import net.bytebuddy.implementation.bind.annotation.This;
 import net.bytebuddy.matcher.ElementMatchers;
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
 import org.apache.shardingsphere.agent.api.advice.type.ConstructorAdvice;
+import org.apache.shardingsphere.agent.api.plugin.AgentPluginEnable;
 import org.apache.shardingsphere.agent.core.advisor.executor.AdviceExecutor;
-import org.apache.shardingsphere.agent.core.plugin.PluginContext;
 
 import java.util.Collection;
 import java.util.Map;
@@ -54,14 +54,12 @@ public final class ConstructorAdviceExecutor implements 
AdviceExecutor {
      */
     @RuntimeType
     public void advice(@This final TargetAdviceObject target, @AllArguments 
final Object[] args) {
-        boolean adviceEnabled = PluginContext.getInstance().isPluginEnabled();
-        if (!adviceEnabled) {
-            return;
-        }
         try {
             for (Entry<String, Collection<ConstructorAdvice>> entry : 
advices.entrySet()) {
                 for (ConstructorAdvice each : entry.getValue()) {
-                    each.onConstructor(target, args, entry.getKey());
+                    if (isPluginEnabled(each)) {
+                        each.onConstructor(target, args, entry.getKey());
+                    }
                 }
             }
             // CHECKSTYLE:OFF
@@ -71,6 +69,10 @@ public final class ConstructorAdviceExecutor implements 
AdviceExecutor {
         }
     }
     
+    private boolean isPluginEnabled(final ConstructorAdvice advice) {
+        return !(advice instanceof AgentPluginEnable) || ((AgentPluginEnable) 
advice).isPluginEnabled();
+    }
+    
     @Override
     public Builder<?> intercept(final Builder<?> builder, final 
MethodDescription pointcut) {
         return 
builder.constructor(ElementMatchers.is(pointcut)).intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.withDefaultConfiguration().to(this)));
diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutor.java
 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutor.java
index e0d0156e386..051ba01bf83 100644
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutor.java
+++ 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutor.java
@@ -28,10 +28,10 @@ import 
net.bytebuddy.implementation.bind.annotation.RuntimeType;
 import net.bytebuddy.implementation.bind.annotation.SuperCall;
 import net.bytebuddy.implementation.bind.annotation.This;
 import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.api.plugin.AgentPluginEnable;
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
 import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
 import org.apache.shardingsphere.agent.core.advisor.executor.AdviceExecutor;
-import org.apache.shardingsphere.agent.core.plugin.PluginContext;
 
 import java.lang.reflect.Method;
 import java.util.Collection;
@@ -62,24 +62,17 @@ public final class InstanceMethodAdviceExecutor implements 
AdviceExecutor {
     @RuntimeType
     @SneakyThrows
     public Object advice(@This final TargetAdviceObject target, @Origin final 
Method method, @AllArguments final Object[] args, @SuperCall final Callable<?> 
callable) {
-        boolean adviceEnabled = PluginContext.getInstance().isPluginEnabled();
-        if (adviceEnabled) {
-            adviceBefore(target, method, args);
-        }
+        adviceBefore(target, method, args);
         Object result = null;
         try {
             result = callable.call();
             // CHECKSTYLE:OFF
         } catch (final Throwable ex) {
             // CHECKSTYLE:ON
-            if (adviceEnabled) {
-                adviceThrow(target, method, args, ex);
-            }
+            adviceThrow(target, method, args, ex);
             throw ex;
         } finally {
-            if (adviceEnabled) {
-                adviceAfter(target, method, args, result);
-            }
+            adviceAfter(target, method, args, result);
         }
         return result;
     }
@@ -88,7 +81,9 @@ public final class InstanceMethodAdviceExecutor implements 
AdviceExecutor {
         try {
             for (Entry<String, Collection<InstanceMethodAdvice>> entry : 
advices.entrySet()) {
                 for (InstanceMethodAdvice each : entry.getValue()) {
-                    each.beforeMethod(target, method, args, entry.getKey());
+                    if (isPluginEnabled(each)) {
+                        each.beforeMethod(target, method, args, 
entry.getKey());
+                    }
                 }
             }
             // CHECKSTYLE:OFF
@@ -102,7 +97,9 @@ public final class InstanceMethodAdviceExecutor implements 
AdviceExecutor {
         try {
             for (Entry<String, Collection<InstanceMethodAdvice>> entry : 
advices.entrySet()) {
                 for (InstanceMethodAdvice each : entry.getValue()) {
-                    each.onThrowing(target, method, args, ex, entry.getKey());
+                    if (isPluginEnabled(each)) {
+                        each.onThrowing(target, method, args, ex, 
entry.getKey());
+                    }
                 }
             }
             // CHECKSTYLE:OFF
@@ -116,9 +113,10 @@ public final class InstanceMethodAdviceExecutor implements 
AdviceExecutor {
         try {
             for (Entry<String, Collection<InstanceMethodAdvice>> entry : 
advices.entrySet()) {
                 for (InstanceMethodAdvice each : entry.getValue()) {
-                    each.afterMethod(target, method, args, result, 
entry.getKey());
+                    if (isPluginEnabled(each)) {
+                        each.afterMethod(target, method, args, result, 
entry.getKey());
+                    }
                 }
-                
             }
             // CHECKSTYLE:OFF
         } catch (final Throwable ex) {
@@ -127,6 +125,10 @@ public final class InstanceMethodAdviceExecutor implements 
AdviceExecutor {
         }
     }
     
+    private boolean isPluginEnabled(final InstanceMethodAdvice advice) {
+        return !(advice instanceof AgentPluginEnable) || ((AgentPluginEnable) 
advice).isPluginEnabled();
+    }
+    
     @Override
     public Builder<?> intercept(final Builder<?> builder, final 
MethodDescription pointcut) {
         return 
builder.method(ElementMatchers.is(pointcut)).intercept(MethodDelegation.withDefaultConfiguration().to(this));
diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/StaticMethodAdviceExecutor.java
 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/StaticMethodAdviceExecutor.java
index 2d681c338f3..55a61a5e2b2 100644
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/StaticMethodAdviceExecutor.java
+++ 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/StaticMethodAdviceExecutor.java
@@ -27,9 +27,9 @@ import net.bytebuddy.implementation.bind.annotation.Origin;
 import net.bytebuddy.implementation.bind.annotation.RuntimeType;
 import net.bytebuddy.implementation.bind.annotation.SuperCall;
 import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.api.plugin.AgentPluginEnable;
 import org.apache.shardingsphere.agent.api.advice.type.StaticMethodAdvice;
 import org.apache.shardingsphere.agent.core.advisor.executor.AdviceExecutor;
-import org.apache.shardingsphere.agent.core.plugin.PluginContext;
 
 import java.lang.reflect.Method;
 import java.util.Collection;
@@ -60,24 +60,17 @@ public final class StaticMethodAdviceExecutor implements 
AdviceExecutor {
     @RuntimeType
     @SneakyThrows
     public Object advice(@Origin final Class<?> klass, @Origin final Method 
method, @AllArguments final Object[] args, @SuperCall final Callable<?> 
callable) {
-        boolean adviceEnabled = PluginContext.getInstance().isPluginEnabled();
-        if (adviceEnabled) {
-            adviceBefore(klass, method, args);
-        }
+        adviceBefore(klass, method, args);
         Object result = null;
         try {
             result = callable.call();
             // CHECKSTYLE:OFF
         } catch (final Throwable ex) {
             // CHECKSTYLE:ON
-            if (adviceEnabled) {
-                adviceThrow(klass, method, args, ex);
-            }
+            adviceThrow(klass, method, args, ex);
             throw ex;
         } finally {
-            if (adviceEnabled) {
-                adviceAfter(klass, method, args, result);
-            }
+            adviceAfter(klass, method, args, result);
         }
         return result;
     }
@@ -86,7 +79,9 @@ public final class StaticMethodAdviceExecutor implements 
AdviceExecutor {
         try {
             for (Entry<String, Collection<StaticMethodAdvice>> entry : 
advices.entrySet()) {
                 for (StaticMethodAdvice each : entry.getValue()) {
-                    each.beforeMethod(klass, method, args, entry.getKey());
+                    if (isPluginEnabled(each)) {
+                        each.beforeMethod(klass, method, args, entry.getKey());
+                    }
                 }
             }
             // CHECKSTYLE:OFF
@@ -100,7 +95,9 @@ public final class StaticMethodAdviceExecutor implements 
AdviceExecutor {
         try {
             for (Entry<String, Collection<StaticMethodAdvice>> entry : 
advices.entrySet()) {
                 for (StaticMethodAdvice each : entry.getValue()) {
-                    each.onThrowing(klass, method, args, ex, entry.getKey());
+                    if (isPluginEnabled(each)) {
+                        each.onThrowing(klass, method, args, ex, 
entry.getKey());
+                    }
                 }
             }
             // CHECKSTYLE:OFF
@@ -114,7 +111,9 @@ public final class StaticMethodAdviceExecutor implements 
AdviceExecutor {
         try {
             for (Entry<String, Collection<StaticMethodAdvice>> entry : 
advices.entrySet()) {
                 for (StaticMethodAdvice each : entry.getValue()) {
-                    each.afterMethod(klass, method, args, result, 
entry.getKey());
+                    if (isPluginEnabled(each)) {
+                        each.afterMethod(klass, method, args, result, 
entry.getKey());
+                    }
                 }
             }
             // CHECKSTYLE:OFF
@@ -124,6 +123,10 @@ public final class StaticMethodAdviceExecutor implements 
AdviceExecutor {
         }
     }
     
+    private boolean isPluginEnabled(final StaticMethodAdvice advice) {
+        return !(advice instanceof AgentPluginEnable) || ((AgentPluginEnable) 
advice).isPluginEnabled();
+    }
+    
     @Override
     public Builder<?> intercept(final Builder<?> builder, final 
MethodDescription pointcut) {
         return 
builder.method(ElementMatchers.is(pointcut)).intercept(MethodDelegation.withDefaultConfiguration().to(this));
diff --git 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/PluginContextTest.java
 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/PluginContextTest.java
deleted file mode 100644
index cdfd7520fc2..00000000000
--- 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/PluginContextTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.shardingsphere.agent.core.plugin;
-
-import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.test.mock.AutoMockExtension;
-import org.apache.shardingsphere.test.mock.StaticMockSettings;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(AutoMockExtension.class)
-@StaticMockSettings(ProxyContext.class)
-class PluginContextTest {
-    
-    @AfterEach
-    void reset() {
-        PluginContext.getInstance().setContextManager(null);
-    }
-    
-    @Test
-    void assertPluginEnabledIsTrue() {
-        PluginContext.getInstance().setEnhancedForProxy(true);
-        ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
-        
when(contextManager.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.AGENT_PLUGINS_ENABLED)).thenReturn(true);
-        
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
-        assertTrue(PluginContext.getInstance().isPluginEnabled());
-    }
-    
-    @Test
-    void assertPluginEnabledIsFalse() {
-        PluginContext.getInstance().setEnhancedForProxy(true);
-        ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
-        
when(contextManager.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.AGENT_PLUGINS_ENABLED)).thenReturn(false);
-        
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
-        assertFalse(PluginContext.getInstance().isPluginEnabled());
-    }
-}
diff --git 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/advice/AbstractInstanceMethodAdvice.java
similarity index 62%
copy from 
agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
copy to 
agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/advice/AbstractInstanceMethodAdvice.java
index 2b1f2518187..860e8b5b1c9 100644
--- 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
+++ 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/advice/AbstractInstanceMethodAdvice.java
@@ -15,22 +15,16 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.agent.plugin.logging.file;
+package org.apache.shardingsphere.agent.plugin.core.advice;
 
-import org.apache.shardingsphere.agent.api.PluginConfiguration;
-import org.apache.shardingsphere.agent.spi.PluginLifecycleService;
+import org.apache.shardingsphere.agent.api.plugin.AgentPluginEnable;
+import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import org.apache.shardingsphere.agent.plugin.core.context.PluginContext;
 
-/**
- * File logging plugin lifecycle service.
- */
-public final class FileLoggingPluginLifecycleService implements 
PluginLifecycleService {
-    
-    @Override
-    public void start(final PluginConfiguration pluginConfig, final boolean 
isEnhancedForProxy) {
-    }
+public abstract class AbstractInstanceMethodAdvice implements 
InstanceMethodAdvice, AgentPluginEnable {
     
     @Override
-    public String getType() {
-        return "File";
+    public boolean isPluginEnabled() {
+        return PluginContext.getInstance().isPluginEnabled();
     }
 }
diff --git 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/advice/AbstractStaticMethodAdvice.java
similarity index 62%
copy from 
agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
copy to 
agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/advice/AbstractStaticMethodAdvice.java
index 2b1f2518187..c3d9dbae77a 100644
--- 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
+++ 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/advice/AbstractStaticMethodAdvice.java
@@ -15,22 +15,16 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.agent.plugin.logging.file;
+package org.apache.shardingsphere.agent.plugin.core.advice;
 
-import org.apache.shardingsphere.agent.api.PluginConfiguration;
-import org.apache.shardingsphere.agent.spi.PluginLifecycleService;
+import org.apache.shardingsphere.agent.api.plugin.AgentPluginEnable;
+import org.apache.shardingsphere.agent.api.advice.type.StaticMethodAdvice;
+import org.apache.shardingsphere.agent.plugin.core.context.PluginContext;
 
-/**
- * File logging plugin lifecycle service.
- */
-public final class FileLoggingPluginLifecycleService implements 
PluginLifecycleService {
-    
-    @Override
-    public void start(final PluginConfiguration pluginConfig, final boolean 
isEnhancedForProxy) {
-    }
+public abstract class AbstractStaticMethodAdvice implements 
StaticMethodAdvice, AgentPluginEnable {
     
     @Override
-    public String getType() {
-        return "File";
+    public boolean isPluginEnabled() {
+        return PluginContext.getInstance().isPluginEnabled();
     }
 }
diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginContext.java
 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/PluginContext.java
similarity index 76%
rename from 
agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginContext.java
rename to 
agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/PluginContext.java
index 12ff8cc2818..68496405788 100644
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginContext.java
+++ 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/PluginContext.java
@@ -15,12 +15,12 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.agent.core.plugin;
+package org.apache.shardingsphere.agent.plugin.core.context;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
-import org.apache.shardingsphere.agent.core.util.AgentReflectionUtils;
+import org.apache.shardingsphere.agent.plugin.core.util.AgentReflectionUtils;
 import org.apache.shardingsphere.driver.ShardingSphereDriver;
 import org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache;
 import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
@@ -43,10 +43,10 @@ public final class PluginContext {
     
     private static final PluginContext INSTANCE = new PluginContext();
     
-    private boolean enhancedForProxy;
-    
     private ContextManager contextManager;
     
+    private boolean isEnhancedForProxy;
+    
     /**
      * Get instance of plugin context.
      *
@@ -59,7 +59,7 @@ public final class PluginContext {
     /**
      * Check if the plugin is enabled.
      *
-     * @return the plugin enable value
+     * @return true or false
      */
     public boolean isPluginEnabled() {
         if (null == contextManager) {
@@ -68,18 +68,22 @@ public final class PluginContext {
         return null == contextManager || 
contextManager.getMetaDataContexts().getMetaData().getProps().<Boolean>getValue(ConfigurationPropertyKey.AGENT_PLUGINS_ENABLED);
     }
     
-    private Optional<ContextManager> getContextManager() {
-        if (enhancedForProxy) {
+    /**
+     * Get context manager.
+     *
+     * @return ContextManager
+     */
+    public Optional<ContextManager> getContextManager() {
+        if (isEnhancedForProxy) {
             return 
Optional.ofNullable(ProxyContext.getInstance().getContextManager());
         }
         Optional<ShardingSphereDriver> shardingSphereDriver = 
getShardingSphereDriver();
-        if (!shardingSphereDriver.isPresent()) {
-            return Optional.empty();
+        if (shardingSphereDriver.isPresent()) {
+            DriverDataSourceCache dataSourceCache = 
AgentReflectionUtils.getFieldValue(shardingSphereDriver.get(), 
"dataSourceCache");
+            Map<String, DataSource> dataSourceMap = 
AgentReflectionUtils.getFieldValue(dataSourceCache, "dataSourceMap");
+            return dataSourceMap.isEmpty() ? Optional.empty() : 
Optional.ofNullable(AgentReflectionUtils.getFieldValue(dataSourceMap.values().iterator().next(),
 "contextManager"));
         }
-        DriverDataSourceCache dataSourceCache = 
AgentReflectionUtils.getFieldValue(shardingSphereDriver.get(), 
"dataSourceCache");
-        Map<String, DataSource> dataSourceMap = 
AgentReflectionUtils.getFieldValue(dataSourceCache, "dataSourceMap");
-        return dataSourceMap.isEmpty() ? Optional.empty() : 
Optional.ofNullable(AgentReflectionUtils.getFieldValue(dataSourceMap.values().iterator().next(),
 "contextManager"));
-        
+        return Optional.empty();
     }
     
     private Optional<ShardingSphereDriver> getShardingSphereDriver() {
diff --git 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
 
b/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
index 2b1f2518187..297761479c7 100644
--- 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
+++ 
b/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleService.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.logging.file;
 
 import org.apache.shardingsphere.agent.api.PluginConfiguration;
+import org.apache.shardingsphere.agent.plugin.core.context.PluginContext;
 import org.apache.shardingsphere.agent.spi.PluginLifecycleService;
 
 /**
@@ -27,6 +28,7 @@ public final class FileLoggingPluginLifecycleService 
implements PluginLifecycleS
     
     @Override
     public void start(final PluginConfiguration pluginConfig, final boolean 
isEnhancedForProxy) {
+        PluginContext.getInstance().setEnhancedForProxy(isEnhancedForProxy);
     }
     
     @Override
diff --git 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdvice.java
 
b/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdvice.java
index 9751a95c9f9..159624b5f78 100644
--- 
a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdvice.java
+++ 
b/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.logging.file.advice;
 
 import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.agent.api.advice.type.StaticMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractStaticMethodAdvice;
 import org.apache.shardingsphere.agent.plugin.core.recorder.MethodTimeRecorder;
 
 import java.lang.reflect.Method;
@@ -27,7 +27,7 @@ import java.lang.reflect.Method;
  * Meta data contexts factory advice.
  */
 @Slf4j
-public final class MetaDataContextsFactoryAdvice implements StaticMethodAdvice 
{
+public final class MetaDataContextsFactoryAdvice extends 
AbstractStaticMethodAdvice {
     
     private final MethodTimeRecorder methodTimeRecorder = new 
MethodTimeRecorder(MetaDataContextsFactoryAdvice.class);
     
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
index 343e71c2093..bb995a0d913 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -32,7 +32,7 @@ import java.util.Arrays;
 /**
  * Route result count advice.
  */
-public final class RouteResultCountAdvice implements InstanceMethodAdvice {
+public final class RouteResultCountAdvice extends AbstractInstanceMethodAdvice 
{
     
     private final MetricConfiguration routedResultConfig = new 
MetricConfiguration("routed_result_total",
             MetricCollectorType.COUNTER, "Total count of routed result", 
Arrays.asList("object", "name"));
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
index 554c9463ecd..464a0e8a10e 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import org.apache.shardingsphere.agent.plugin.core.util.SQLStatementUtils;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
@@ -33,7 +33,7 @@ import java.util.Optional;
 /**
  * SQL parse count advice.
  */
-public final class SQLParseCountAdvice implements InstanceMethodAdvice {
+public final class SQLParseCountAdvice extends AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("parsed_sql_total",
             MetricCollectorType.COUNTER, "Total count of parsed SQL", 
Collections.singletonList("type"), Collections.emptyMap());
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
index 885d015aa8c..3805a484c88 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import org.apache.shardingsphere.agent.plugin.core.util.SQLStatementUtils;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
@@ -34,7 +34,7 @@ import java.util.Optional;
 /**
  * SQL route count advice.
  */
-public final class SQLRouteCountAdvice implements InstanceMethodAdvice {
+public final class SQLRouteCountAdvice extends AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("routed_sql_total",
             MetricCollectorType.COUNTER, "Total count of routed SQL", 
Collections.singletonList("type"), Collections.emptyMap());
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdvice.java
index be5f6adbbea..3cc70c46bfd 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -30,7 +30,7 @@ import java.util.Collections;
 /**
  * Abstract execute count advice for ShardingSphere-JDBC.
  */
-public abstract class AbstractExecuteCountAdvice implements 
InstanceMethodAdvice {
+public abstract class AbstractExecuteCountAdvice extends 
AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("jdbc_statement_execute_total", MetricCollectorType.COUNTER,
             "Total number of statement execute", 
Collections.singletonList("statement_type"));
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdvice.java
index 7cefa68af77..3ec1523148d 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -30,7 +30,7 @@ import java.util.Collections;
 /**
  * Abstract execute errors count advice for ShardingSphere-JDBC.
  */
-public abstract class AbstractExecuteErrorsCountAdvice implements 
InstanceMethodAdvice {
+public abstract class AbstractExecuteErrorsCountAdvice extends 
AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("jdbc_statement_execute_errors_total", 
MetricCollectorType.COUNTER,
             "Total number of statement execute error", 
Collections.singletonList("statement_type"));
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
index 8f965cdb3ce..06ca179d1d3 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import org.apache.shardingsphere.agent.plugin.core.recorder.MethodTimeRecorder;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.HistogramMetricsCollector;
@@ -33,7 +33,7 @@ import java.util.Map;
 /**
  * Abstract execute latency histogram advice for ShardingSphere-JDBC.
  */
-public abstract class AbstractExecuteLatencyHistogramAdvice implements 
InstanceMethodAdvice {
+public abstract class AbstractExecuteLatencyHistogramAdvice extends 
AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("jdbc_statement_execute_latency_millis", 
MetricCollectorType.HISTOGRAM,
             "Statement execute latency millis histogram", 
Collections.singletonMap("buckets", getBuckets()));
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdvice.java
index 55a7cf5c368..f74abc52a9a 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -30,7 +30,7 @@ import java.util.Collections;
 /**
  * Abstract transactions count advice for ShardingSphere-JDBC.
  */
-public abstract class AbstractTransactionsCountAdvice implements 
InstanceMethodAdvice {
+public abstract class AbstractTransactionsCountAdvice extends 
AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("jdbc_transactions_total", MetricCollectorType.COUNTER,
             "Total transactions of ShardingSphere-JDBC", 
Collections.singletonList("type"));
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
index bbde9a20542..a7c20d09c47 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -30,7 +30,7 @@ import java.util.Collections;
 /**
  * Commit transactions count advice for ShardingSphere-Proxy.
  */
-public final class CommitTransactionsCountAdvice implements 
InstanceMethodAdvice {
+public final class CommitTransactionsCountAdvice extends 
AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("proxy_transactions_total",
             MetricCollectorType.COUNTER, "Total transactions of 
ShardingSphere-Proxy", Collections.singletonList("type"), 
Collections.emptyMap());
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
index 23ad3da638b..3aad6ce0b02 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -30,7 +30,7 @@ import java.util.Collections;
 /**
  * Current connections count advice for ShardingSphere-Proxy.
  */
-public final class CurrentConnectionsCountAdvice implements 
InstanceMethodAdvice {
+public final class CurrentConnectionsCountAdvice extends 
AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("proxy_current_connections",
             MetricCollectorType.GAUGE, "Current connections of 
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
index 425103378f3..9c0c0b674bc 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -30,7 +30,7 @@ import java.util.Collections;
 /**
  * Execute errors count advice for ShardingSphere-Proxy.
  */
-public final class ExecuteErrorsCountAdvice implements InstanceMethodAdvice {
+public final class ExecuteErrorsCountAdvice extends 
AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("proxy_execute_errors_total",
             MetricCollectorType.COUNTER, "Total execute errors of 
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
index 757f604cc95..55697a60253 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import org.apache.shardingsphere.agent.plugin.core.recorder.MethodTimeRecorder;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.HistogramMetricsCollector;
@@ -34,7 +34,7 @@ import java.util.Map;
 /**
  * Execute latency histogram advance for ShardingSphere-Proxy.
  */
-public final class ExecuteLatencyHistogramAdvice implements 
InstanceMethodAdvice {
+public final class ExecuteLatencyHistogramAdvice extends 
AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("proxy_execute_latency_millis",
             MetricCollectorType.HISTOGRAM, "Execute latency millis histogram 
of ShardingSphere-Proxy", Collections.emptyList(), 
Collections.singletonMap("buckets", getBuckets()));
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
index 267bc99945b..f0fbacb5208 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -30,7 +30,7 @@ import java.util.Collections;
 /**
  * Requests count advice for ShardingSphere-Proxy.
  */
-public final class RequestsCountAdvice implements InstanceMethodAdvice {
+public final class RequestsCountAdvice extends AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("proxy_requests_total",
             MetricCollectorType.COUNTER, "Total requests of 
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
index d40a8fa2ba4..d37d2c8c955 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -30,7 +30,7 @@ import java.util.Collections;
 /**
  * Rollback transactions count advice for ShardingSphere-Proxy.
  */
-public final class RollbackTransactionsCountAdvice implements 
InstanceMethodAdvice {
+public final class RollbackTransactionsCountAdvice extends 
AbstractInstanceMethodAdvice {
     
     private final MetricConfiguration config = new 
MetricConfiguration("proxy_transactions_total",
             MetricCollectorType.COUNTER, "Total transactions of 
ShardingSphere-Proxy", Collections.singletonList("type"), 
Collections.emptyMap());
diff --git 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
index f5ad8f8dfb8..1da1832be02 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
@@ -23,6 +23,7 @@ import io.prometheus.client.hotspot.DefaultExports;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.agent.api.PluginConfiguration;
 import 
org.apache.shardingsphere.agent.plugin.core.config.validator.PluginConfigurationValidator;
+import org.apache.shardingsphere.agent.plugin.core.context.PluginContext;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.BuildInfoExporter;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.jdbc.JDBCMetaDataInfoExporter;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.jdbc.JDBCStateExporter;
@@ -46,6 +47,7 @@ public final class PrometheusPluginLifecycleService 
implements PluginLifecycleSe
     
     @Override
     public void start(final PluginConfiguration pluginConfig, final boolean 
isEnhancedForProxy) {
+        PluginContext.getInstance().setEnhancedForProxy(isEnhancedForProxy);
         PluginConfigurationValidator.validatePort(getType(), pluginConfig);
         startServer(pluginConfig, isEnhancedForProxy);
     }
diff --git a/agent/plugins/pom.xml b/agent/plugins/pom.xml
index 212240e8505..948373fe7b8 100644
--- a/agent/plugins/pom.xml
+++ b/agent/plugins/pom.xml
@@ -47,6 +47,31 @@
             <artifactId>byte-buddy</artifactId>
             <scope>provided</scope>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-proxy-backend-core</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.h2database</groupId>
+                    <artifactId>h2</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-jdbc-core</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.h2database</groupId>
+                    <artifactId>h2</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
     </dependencies>
     
     <build>
diff --git 
a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingJDBCExecutorCallbackAdvice.java
 
b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingJDBCExecutorCallbackAdvice.java
index c2c9c8005e4..de151c669c7 100644
--- 
a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingJDBCExecutorCallbackAdvice.java
+++ 
b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingJDBCExecutorCallbackAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.tracing.core.advice;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import org.apache.shardingsphere.agent.plugin.core.util.AgentReflectionUtils;
 import org.apache.shardingsphere.agent.plugin.tracing.core.RootSpanContext;
 import 
org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties;
@@ -33,7 +33,7 @@ import java.lang.reflect.Method;
  * 
  * @param <T> type of root span
  */
-public abstract class TracingJDBCExecutorCallbackAdvice<T> implements 
InstanceMethodAdvice {
+public abstract class TracingJDBCExecutorCallbackAdvice<T> extends 
AbstractInstanceMethodAdvice {
     
     protected static final String OPERATION_NAME = 
"/ShardingSphere/executeSQL/";
     
diff --git 
a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingRootSpanAdvice.java
 
b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingRootSpanAdvice.java
index 6a1a234f35b..f8702d27054 100644
--- 
a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingRootSpanAdvice.java
+++ 
b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingRootSpanAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.tracing.core.advice;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import org.apache.shardingsphere.agent.plugin.tracing.core.RootSpanContext;
 
 import java.lang.reflect.Method;
@@ -28,7 +28,7 @@ import java.lang.reflect.Method;
  * 
  * @param <T> type of span
  */
-public abstract class TracingRootSpanAdvice<T> implements InstanceMethodAdvice 
{
+public abstract class TracingRootSpanAdvice<T> extends 
AbstractInstanceMethodAdvice {
     
     protected static final String OPERATION_NAME = 
"/ShardingSphere/rootInvoke/";
     
diff --git 
a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingSQLParserEngineAdvice.java
 
b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingSQLParserEngineAdvice.java
index a6f8a02ad4e..39ba1fe25ef 100644
--- 
a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingSQLParserEngineAdvice.java
+++ 
b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingSQLParserEngineAdvice.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.plugin.tracing.core.advice;
 
 import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
+import 
org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
 import org.apache.shardingsphere.agent.plugin.tracing.core.RootSpanContext;
 
 import java.lang.reflect.Method;
@@ -28,7 +28,7 @@ import java.lang.reflect.Method;
  * 
  * @param <T> type of root span
  */
-public abstract class TracingSQLParserEngineAdvice<T> implements 
InstanceMethodAdvice {
+public abstract class TracingSQLParserEngineAdvice<T> extends 
AbstractInstanceMethodAdvice {
     
     protected static final String OPERATION_NAME = "/ShardingSphere/parseSQL/";
     
diff --git 
a/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/OpenTelemetryTracingPluginLifecycleService.java
 
b/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/OpenTelemetryTracingPluginLifecycleService.java
index d73bfbaa4a2..fdeb4531e0d 100644
--- 
a/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/OpenTelemetryTracingPluginLifecycleService.java
+++ 
b/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/OpenTelemetryTracingPluginLifecycleService.java
@@ -20,6 +20,7 @@ package 
org.apache.shardingsphere.agent.plugin.tracing.opentelemetry;
 import io.opentelemetry.sdk.OpenTelemetrySdk;
 import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
 import org.apache.shardingsphere.agent.api.PluginConfiguration;
+import org.apache.shardingsphere.agent.plugin.core.context.PluginContext;
 import 
org.apache.shardingsphere.agent.plugin.tracing.opentelemetry.constant.OpenTelemetryConstants;
 import org.apache.shardingsphere.agent.spi.PluginLifecycleService;
 
@@ -30,6 +31,7 @@ public final class OpenTelemetryTracingPluginLifecycleService 
implements PluginL
     
     @Override
     public void start(final PluginConfiguration pluginConfig, final boolean 
isEnhancedForProxy) {
+        PluginContext.getInstance().setEnhancedForProxy(isEnhancedForProxy);
         pluginConfig.getProps().forEach((key, value) -> 
setSystemProperty(String.valueOf(key), String.valueOf(value)));
         OpenTelemetrySdk openTelemetrySdk = 
AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk();
         openTelemetrySdk.getTracer(OpenTelemetryConstants.TRACER_NAME);

Reply via email to