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

xiaoyu 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 44adab0  Provide Jaeger as tracing plugin  (#8608)
44adab0 is described below

commit 44adab00a8f3800715d57f1b65d1370b4064b1e7
Author: Daming <[email protected]>
AuthorDate: Mon Dec 14 17:26:26 2020 +0800

    Provide Jaeger as tracing plugin  (#8608)
    
    * provide jaeger plugin
    
    * provide jaeger plugin
    
    * fix checkstyle
    
    * fix checkstyle
    
    * fix license missing
    
    * revert
    
    * Update pom.xml
---
 shardingsphere-agent/pom.xml                       | 12 ++++
 .../agent/bootstrap/ShardingSphereAgent.java       |  2 +-
 .../shardingsphere/agent/core/LoggingListener.java |  4 +-
 .../agent/core/config/AgentConfiguration.java      | 14 +++++
 .../agent/core/plugin/AgentPluginLoader.java       | 28 +++++----
 .../src/main/resources/conf/agent.yaml             |  9 +++
 .../shardingsphere-agent-plugin-tracers/pom.xml    |  2 +-
 .../pom.xml                                        | 18 +++++-
 .../plugin/trace/JaegerPluginDefinition.java}      | 30 ++++++---
 .../agent/plugin/trace/JaegerTracerService.java    | 59 ++++++++++++++++++
 .../agent/plugin/trace/ShardingErrorSpan.java      | 52 ++++++++++++++++
 .../trace/advice/CommandExecutorTaskAdvice.java}   | 32 +++++++---
 .../trace/advice/JDBCExecutorCallbackAdvice.java   | 72 ++++++++++++++++++++++
 .../trace/advice/SQLParserEngineAdvice.java}       | 30 ++++++---
 .../trace/constant/ShardingErrorLogTagKeys.java}   | 34 +++++-----
 .../agent/plugin/trace/constant/ShardingTags.java} | 40 ++++++------
 .../shardingsphere-tracing/pom.xml                 |  1 -
 17 files changed, 357 insertions(+), 82 deletions(-)

diff --git a/shardingsphere-agent/pom.xml b/shardingsphere-agent/pom.xml
index e500aa6..1827ccd 100644
--- a/shardingsphere-agent/pom.xml
+++ b/shardingsphere-agent/pom.xml
@@ -30,6 +30,7 @@
     <packaging>pom</packaging>
 
     <properties>
+        <maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
         <shade.package>org.apache.shardingsphere.dependencies</shade.package>
     </properties>
 
@@ -53,4 +54,15 @@
             <scope>test</scope>
         </dependency>
     </dependencies>
+
+    <build>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <artifactId>maven-shade-plugin</artifactId>
+                    <version>${maven-shade-plugin.version}</version>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
 </project>
diff --git 
a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
 
b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
index 56ac8c4..9f7affb 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
@@ -54,12 +54,12 @@ public class ShardingSphereAgent {
             
.or(ElementMatchers.nameStartsWith("org.apache.shardingsphere.agent."));
         AgentPluginLoader agentPluginLoader = AgentPluginLoader.getInstance();
         agentPluginLoader.loadAllPlugins();
-        agentPluginLoader.initialAllServices();
         builder.type(agentPluginLoader.typeMatcher())
                .transform(new ShardingSphereTransformer(agentPluginLoader))
                .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
                .with(new LoggingListener())
                .installOn(instrumentation);
+        agentPluginLoader.initialAllServices();
         agentPluginLoader.startAllServices();
         Runtime.getRuntime().addShutdownHook(new 
Thread(agentPluginLoader::shutdownAllServices));
     }
diff --git 
a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/LoggingListener.java
 
b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/LoggingListener.java
index 43411e7..cb98daf 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/LoggingListener.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/LoggingListener.java
@@ -36,9 +36,7 @@ public class LoggingListener implements AgentBuilder.Listener 
{
     
     @Override
     public void onTransformation(final TypeDescription typeDescription, final 
ClassLoader classLoader, final JavaModule module, final boolean loaded, final 
DynamicType dynamicType) {
-        if (log.isDebugEnabled()) {
-            log.debug("On transformation class {}.", 
typeDescription.getTypeName());
-        }
+        log.info("On transformation class {}.", typeDescription.getTypeName());
     }
     
     @Override
diff --git 
a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
 
b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
index fcd8184..077dd35 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.agent.core.config;
 import lombok.Data;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * Agent configuration.
@@ -31,6 +32,8 @@ public class AgentConfiguration {
     
     private MetricsConfiguration metrics;
     
+    private TracingConfiguration tracing;
+    
     private List<String> activatedPlugins;
     
     @Data
@@ -44,4 +47,15 @@ public class AgentConfiguration {
         
         private boolean jvmInformationCollectorEnabled;
     }
+    
+    @Data
+    public static class TracingConfiguration {
+        
+        private String agentHost = "localhost";
+        
+        private int agentPort = 5775;
+        
+        private Map<String, String> extra;
+        
+    }
 }
diff --git 
a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
 
b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
index 199887e..84d7625 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
@@ -75,6 +75,7 @@ public final class AgentPluginLoader extends ClassLoader 
implements Closeable {
     private Map<String, PluginAdviceDefinition> pluginDefineMap;
     
     private AgentPluginLoader() {
+        super(AgentPluginLoader.class.getClassLoader());
     }
     
     @Override
@@ -172,6 +173,7 @@ public final class AgentPluginLoader extends ClassLoader 
implements Closeable {
             outputStream.reset();
             JarFile jar = new JarFile(jarFile, true);
             jars.add(new UberJar(jar, jarFile));
+            log.info("Loaded jar {}.", jarFile.getName());
             Attributes attributes = jar.getManifest().getMainAttributes();
             String entrypoint = attributes.getValue("Entrypoint");
             if (Strings.isNullOrEmpty(entrypoint)) {
@@ -184,13 +186,6 @@ public final class AgentPluginLoader extends ClassLoader 
implements Closeable {
                 if (!activatedPlugins.isEmpty() && 
!activatedPlugins.contains(pluginDefinition.getPluginName())) {
                     continue;
                 }
-                pluginDefinition.getAllServices().forEach(klass -> {
-                    try {
-                        services.add(klass.newInstance());
-                    } catch (InstantiationException | IllegalAccessException 
ex) {
-                        log.error("Failed to create service instance, {}.", 
klass.getTypeName(), ex);
-                    }
-                });
                 pluginDefinition.build().forEach(plugin -> {
                     String target = plugin.getClassNameOfTarget();
                     if (pluginAdviceDefinitionMap.containsKey(target)) {
@@ -202,7 +197,18 @@ public final class AgentPluginLoader extends ClassLoader 
implements Closeable {
                         pluginAdviceDefinitionMap.put(target, plugin);
                     }
                 });
-            } catch (final InstantiationException | IllegalAccessException ex) 
{
+                pluginDefinition.getAllServices().forEach(klass -> {
+                    try {
+                        services.add(klass.newInstance());
+                        // CHECKSTYLE:OFF
+                    } catch (final Throwable ex) {
+                        // CHECKSTYLE:ON
+                        log.error("Failed to create service instance, {}.", 
klass, ex);
+                    }
+                });
+                // CHECKSTYLE:OFF
+            } catch (final Throwable ex) {
+                // CHECKSTYLE:ON
                 log.error("Failed to load plugin definition, {}.", entrypoint, 
ex);
             }
         }
@@ -292,7 +298,7 @@ public final class AgentPluginLoader extends ClassLoader 
implements Closeable {
             try {
                 service.setup();
                 // CHECKSTYLE:OFF
-            } catch (final Exception ex) {
+            } catch (final Throwable ex) {
                 // CHECKSTYLE:ON
                 log.error("Failed to initial service.", ex);
             }
@@ -307,7 +313,7 @@ public final class AgentPluginLoader extends ClassLoader 
implements Closeable {
             try {
                 service.start();
                 // CHECKSTYLE:OFF
-            } catch (final Exception ex) {
+            } catch (final Throwable ex) {
                 // CHECKSTYLE:ON
                 log.error("Failed to start service.", ex);
             }
@@ -322,7 +328,7 @@ public final class AgentPluginLoader extends ClassLoader 
implements Closeable {
             try {
                 service.cleanup();
                 // CHECKSTYLE:OFF
-            } catch (final Exception ex) {
+            } catch (final Throwable ex) {
                 // CHECKSTYLE:ON
                 log.error("Failed to shutdown service.", ex);
             }
diff --git 
a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
 
b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
index d4ce979..62873d2 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
+++ 
b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
@@ -21,3 +21,12 @@ metrics:
   host: localhost
   port: 8090
 
+tracing:
+  agentHost: localhost
+  agentPort: 5775
+  extra:
+    JAEGER_SAMPLER_TYPE: const
+    JAEGER_SAMPLER_PARAM: 1
+    JAEGER_REPORTER_LOG_SPANS: true
+    JAEGER_REPORTER_FLUSH_INTERVAL: 1
+    
\ No newline at end of file
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/pom.xml
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/pom.xml
index ad391db..da5d2cb 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/pom.xml
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/pom.xml
@@ -36,7 +36,7 @@
     </properties>
 
     <modules>
-        <module>shardingsphere-agent-tracer-sample</module>
+        <module>shardingsphere-agent-tracer-jaeger</module>
     </modules>
 
     <dependencies>
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/pom.xml
similarity index 68%
rename from 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml
rename to 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/pom.xml
index 6a86735..034b95c 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/pom.xml
@@ -28,10 +28,24 @@
     </parent>
 
     <packaging>jar</packaging>
-    <artifactId>shardingsphere-agent-tracer-sample</artifactId>
+    <artifactId>shardingsphere-agent-tracer-jaeger</artifactId>
 
     <properties>
-        
<entrypoint.class>org.apache.shardingsphere.agent.plugin.trace.SamplePluginDefinition</entrypoint.class>
+        <jaeger-client.version>0.31.0</jaeger-client.version>
+        
<entrypoint.class>org.apache.shardingsphere.agent.plugin.trace.JaegerPluginDefinition</entrypoint.class>
     </properties>
 
+    <dependencies>
+        <dependency>
+            <groupId>io.jaegertracing</groupId>
+            <artifactId>jaeger-client</artifactId>
+            <version>${jaeger-client.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-proxy-frontend-core</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
 </project>
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefinition.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/JaegerPluginDefinition.java
similarity index 51%
copy from 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefinition.java
copy to 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/JaegerPluginDefinition.java
index 96bf11a..c5417e6 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefinition.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/JaegerPluginDefinition.java
@@ -22,19 +22,35 @@ import net.bytebuddy.matcher.ElementMatchers;
 import org.apache.shardingsphere.agent.core.plugin.PluginDefinition;
 
 /**
- * Sample plugin definition.
+ * Jaeger plugin definition.
  */
-public class SamplePluginDefinition extends PluginDefinition {
-
-    public SamplePluginDefinition() {
-        super("sample");
+public class JaegerPluginDefinition extends PluginDefinition {
+    
+    public JaegerPluginDefinition() {
+        super("jaeger");
     }
-
+    
     @Override
     protected void define() {
+        registerService(JaegerTracerService.class);
+        
         
intercept("org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask")
                 .aroundInstanceMethod(ElementMatchers.named("executeCommand"))
-                
.implement("org.apache.shardingsphere.agent.plugin.trace.SampleAdvice")
+                
.implement("org.apache.shardingsphere.agent.plugin.trace.advice.CommandExecutorTaskAdvice")
+                .build();
+        
intercept("org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine")
+                .aroundInstanceMethod(ElementMatchers.named("parse"))
+                
.implement("org.apache.shardingsphere.agent.plugin.trace.advice.SQLParserEngineAdvice")
+                .build();
+        
intercept("org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback")
+                .aroundInstanceMethod(
+                        ElementMatchers.named("execute")
+                                .and(ElementMatchers.takesArgument(
+                                        0,
+                                        
ElementMatchers.named("org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit"))
+                                )
+                )
+                
.implement("org.apache.shardingsphere.agent.plugin.trace.advice.JDBCExecutorCallbackAdvice")
                 .build();
     }
 }
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/JaegerTracerService.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/JaegerTracerService.java
new file mode 100644
index 0000000..1d5a247
--- /dev/null
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/JaegerTracerService.java
@@ -0,0 +1,59 @@
+/*
+ * 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.plugin.trace;
+
+import io.jaegertracing.Configuration;
+import io.opentracing.util.GlobalTracer;
+import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
+import org.apache.shardingsphere.agent.core.plugin.Service;
+import org.apache.shardingsphere.agent.core.utils.SingletonHolder;
+
+/**
+ * Jaeger tracer service.
+ */
+public class JaegerTracerService implements Service {
+    
+    @Override
+    public void setup() {
+        AgentConfiguration configuration = 
SingletonHolder.INSTANCE.get(AgentConfiguration.class);
+        AgentConfiguration.TracingConfiguration tracingConfiguration = 
configuration.getTracing();
+        tracingConfiguration.getExtra().forEach(System::setProperty);
+        Configuration.SamplerConfiguration samplerConfig = 
Configuration.SamplerConfiguration.fromEnv();
+        Configuration.ReporterConfiguration reporterConfig = 
Configuration.ReporterConfiguration.fromEnv()
+                .withSender(
+                        Configuration.SenderConfiguration.fromEnv()
+                                
.withAgentHost(tracingConfiguration.getAgentHost())
+                                
.withAgentPort(tracingConfiguration.getAgentPort())
+                );
+        Configuration config = new 
Configuration(configuration.getApplicationName())
+                .withSampler(samplerConfig)
+                .withReporter(reporterConfig);
+        GlobalTracer.register(config.getTracer());
+    }
+    
+    @Override
+    public void start() {
+    
+    }
+    
+    @Override
+    public void cleanup() {
+    
+    }
+}
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/ShardingErrorSpan.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/ShardingErrorSpan.java
new file mode 100644
index 0000000..5bdcd08
--- /dev/null
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/ShardingErrorSpan.java
@@ -0,0 +1,52 @@
+/*
+ * 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.plugin.trace;
+
+import io.opentracing.Span;
+import io.opentracing.tag.Tags;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.agent.plugin.trace.constant.ShardingErrorLogTagKeys;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Sharding error span.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShardingErrorSpan {
+    
+    /**
+     * Set error.
+     * 
+     * @param span span to be set
+     * @param cause failure cause of span
+     */
+    public static void setError(final Span span, final Throwable cause) {
+        span.setTag(Tags.ERROR.getKey(), true).log(System.currentTimeMillis(), 
getReason(cause));
+    }
+    
+    private static Map<String, ?> getReason(final Throwable cause) {
+        Map<String, String> result = new HashMap<>(3, 1);
+        result.put(ShardingErrorLogTagKeys.EVENT, 
ShardingErrorLogTagKeys.EVENT_ERROR_TYPE);
+        result.put(ShardingErrorLogTagKeys.ERROR_KIND, 
cause.getClass().getName());
+        result.put(ShardingErrorLogTagKeys.MESSAGE, cause.getMessage());
+        return result;
+    }
+}
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleAdvice.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/advice/CommandExecutorTaskAdvice.java
similarity index 58%
copy from 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleAdvice.java
copy to 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/advice/CommandExecutorTaskAdvice.java
index 9e24dbc..532902c 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleAdvice.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/advice/CommandExecutorTaskAdvice.java
@@ -16,31 +16,45 @@
  *
  */
 
-package org.apache.shardingsphere.agent.plugin.trace;
+package org.apache.shardingsphere.agent.plugin.trace.advice;
 
+import io.opentracing.Scope;
+import io.opentracing.tag.Tags;
+import io.opentracing.util.GlobalTracer;
 import org.apache.shardingsphere.agent.core.plugin.advice.MethodAroundAdvice;
 import 
org.apache.shardingsphere.agent.core.plugin.advice.MethodInvocationResult;
 import org.apache.shardingsphere.agent.core.plugin.advice.TargetObject;
+import org.apache.shardingsphere.agent.plugin.trace.ShardingErrorSpan;
+import org.apache.shardingsphere.agent.plugin.trace.constant.ShardingTags;
+import org.apache.shardingsphere.infra.executor.kernel.model.ExecutorDataMap;
 
 import java.lang.reflect.Method;
 
 /**
- * Advice sample.
+ * Command executor task advice.
  */
-public class SampleAdvice implements MethodAroundAdvice {
-
+public class CommandExecutorTaskAdvice implements MethodAroundAdvice {
+    
+    private static final String OPERATION_NAME = "/ShardingSphere/rootInvoke/";
+    
+    private static final String ROOT_SPAN = "_root_span_";
+    
     @Override
     public void beforeMethod(final TargetObject target, final Method method, 
final Object[] args, final MethodInvocationResult result) {
-
+        Scope scope = GlobalTracer.get().buildSpan(OPERATION_NAME)
+                .withTag(Tags.COMPONENT.getKey(), ShardingTags.COMPONENT_NAME)
+                .startActive(true);
+        ExecutorDataMap.getValue().put(ROOT_SPAN, scope.span());
     }
-
+    
     @Override
     public void afterMethod(final TargetObject target, final Method method, 
final Object[] args, final MethodInvocationResult result) {
-
+        GlobalTracer.get().scopeManager().active().close();
+        ExecutorDataMap.getValue().remove(ROOT_SPAN);
     }
-
+    
     @Override
     public void onThrowing(final TargetObject target, final Method method, 
final Object[] args, final Throwable throwable) {
-
+        ShardingErrorSpan.setError(GlobalTracer.get().activeSpan(), throwable);
     }
 }
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/advice/JDBCExecutorCallbackAdvice.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/advice/JDBCExecutorCallbackAdvice.java
new file mode 100644
index 0000000..669730b
--- /dev/null
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/advice/JDBCExecutorCallbackAdvice.java
@@ -0,0 +1,72 @@
+/*
+ * 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.plugin.trace.advice;
+
+import io.opentracing.Scope;
+import io.opentracing.Span;
+import io.opentracing.Tracer;
+import io.opentracing.tag.Tags;
+import io.opentracing.util.GlobalTracer;
+import org.apache.shardingsphere.agent.core.plugin.advice.MethodAroundAdvice;
+import 
org.apache.shardingsphere.agent.core.plugin.advice.MethodInvocationResult;
+import org.apache.shardingsphere.agent.core.plugin.advice.TargetObject;
+import org.apache.shardingsphere.agent.plugin.trace.ShardingErrorSpan;
+import org.apache.shardingsphere.agent.plugin.trace.constant.ShardingTags;
+import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * JDBC executor callback advice.
+ */
+public class JDBCExecutorCallbackAdvice implements MethodAroundAdvice {
+    
+    private static final String OPERATION_NAME = "/ShardingSphere/executeSQL/";
+    
+    @Override
+    public void beforeMethod(final TargetObject target, final Method method, 
final Object[] args, final MethodInvocationResult result) {
+        Span root = (Span) ((Map<String, Object>) args[2]).get("_root_span_");
+        Tracer.SpanBuilder builder = 
GlobalTracer.get().buildSpan(OPERATION_NAME);
+        if ((boolean) args[1]) {
+            builder.asChildOf(root);
+        } else {
+            JDBCExecutionUnit executionUnit = (JDBCExecutionUnit) args[0];
+            ExecutionUnit unit = executionUnit.getExecutionUnit();
+            builder.withTag(Tags.COMPONENT.getKey(), 
ShardingTags.COMPONENT_NAME)
+                    .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
+                    .withTag(Tags.DB_TYPE.getKey(), "sql")
+                    .withTag(Tags.DB_INSTANCE.getKey(), 
unit.getDataSourceName())
+                    .withTag(Tags.DB_STATEMENT.getKey(), 
unit.getSqlUnit().getSql())
+                    .withTag(ShardingTags.DB_BIND_VARIABLES.getKey(), 
unit.getSqlUnit().getParameters().toString());
+        }
+        target.setAttachment(builder.startActive(true));
+    }
+    
+    @Override
+    public void afterMethod(final TargetObject target, final Method method, 
final Object[] args, final MethodInvocationResult result) {
+        ((Scope) target.getAttachment()).close();
+    }
+    
+    @Override
+    public void onThrowing(final TargetObject target, final Method method, 
final Object[] args, final Throwable throwable) {
+        ShardingErrorSpan.setError(GlobalTracer.get().activeSpan(), throwable);
+    }
+}
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleAdvice.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/advice/SQLParserEngineAdvice.java
similarity index 60%
rename from 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleAdvice.java
rename to 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/advice/SQLParserEngineAdvice.java
index 9e24dbc..9d2e1d4 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleAdvice.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/advice/SQLParserEngineAdvice.java
@@ -16,31 +16,43 @@
  *
  */
 
-package org.apache.shardingsphere.agent.plugin.trace;
+package org.apache.shardingsphere.agent.plugin.trace.advice;
 
+import io.opentracing.Scope;
+import io.opentracing.tag.Tags;
+import io.opentracing.util.GlobalTracer;
 import org.apache.shardingsphere.agent.core.plugin.advice.MethodAroundAdvice;
 import 
org.apache.shardingsphere.agent.core.plugin.advice.MethodInvocationResult;
 import org.apache.shardingsphere.agent.core.plugin.advice.TargetObject;
+import org.apache.shardingsphere.agent.plugin.trace.ShardingErrorSpan;
+import org.apache.shardingsphere.agent.plugin.trace.constant.ShardingTags;
 
 import java.lang.reflect.Method;
 
 /**
- * Advice sample.
+ * SQL parser engine advice.
  */
-public class SampleAdvice implements MethodAroundAdvice {
-
+public class SQLParserEngineAdvice implements MethodAroundAdvice {
+    
+    private static final String OPERATION_NAME = "/ShardingSphere/parseSQL/";
+    
     @Override
     public void beforeMethod(final TargetObject target, final Method method, 
final Object[] args, final MethodInvocationResult result) {
-
+        Scope scope = GlobalTracer.get().buildSpan(OPERATION_NAME)
+                .withTag(Tags.COMPONENT.getKey(), ShardingTags.COMPONENT_NAME)
+                .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
+                .withTag(Tags.DB_STATEMENT.getKey(), String.valueOf(args[0]))
+                .startActive(true);
+        target.setAttachment(scope);
     }
-
+    
     @Override
     public void afterMethod(final TargetObject target, final Method method, 
final Object[] args, final MethodInvocationResult result) {
-
+        ((Scope) target.getAttachment()).close();
     }
-
+    
     @Override
     public void onThrowing(final TargetObject target, final Method method, 
final Object[] args, final Throwable throwable) {
-
+        ShardingErrorSpan.setError(GlobalTracer.get().activeSpan(), throwable);
     }
 }
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleTracer.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/constant/ShardingErrorLogTagKeys.java
similarity index 62%
rename from 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleTracer.java
rename to 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/constant/ShardingErrorLogTagKeys.java
index ceae189..ce3472b 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleTracer.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/constant/ShardingErrorLogTagKeys.java
@@ -13,30 +13,24 @@
  * 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.plugin.trace;
+package org.apache.shardingsphere.agent.plugin.trace.constant;
 
-import org.apache.shardingsphere.agent.core.plugin.Service;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 
 /**
- * Tracer Sample.
+ * Sharding error log tag keys.
  */
-public class SampleTracer implements Service {
-
-    @Override
-    public void setup() {
-
-    }
-
-    @Override
-    public void start() {
-
-    }
-
-    @Override
-    public void cleanup() {
-
-    }
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShardingErrorLogTagKeys {
+    
+    public static final String EVENT = "event";
+    
+    public static final String EVENT_ERROR_TYPE = "error";
+    
+    public static final String ERROR_KIND = "error.kind";
+    
+    public static final String MESSAGE = "message";
 }
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefinition.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/constant/ShardingTags.java
similarity index 53%
rename from 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefinition.java
rename to 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/constant/ShardingTags.java
index 96bf11a..8548593 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefinition.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/trace/constant/ShardingTags.java
@@ -13,28 +13,32 @@
  * 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.plugin.trace;
+package org.apache.shardingsphere.agent.plugin.trace.constant;
 
-import net.bytebuddy.matcher.ElementMatchers;
-import org.apache.shardingsphere.agent.core.plugin.PluginDefinition;
+import io.opentracing.tag.StringTag;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 
 /**
- * Sample plugin definition.
+ * Sharding tags.
  */
-public class SamplePluginDefinition extends PluginDefinition {
-
-    public SamplePluginDefinition() {
-        super("sample");
-    }
-
-    @Override
-    protected void define() {
-        
intercept("org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask")
-                .aroundInstanceMethod(ElementMatchers.named("executeCommand"))
-                
.implement("org.apache.shardingsphere.agent.plugin.trace.SampleAdvice")
-                .build();
-    }
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShardingTags {
+    
+    /**
+     * Component name of ShardingSphere's open tracing tag.
+     */
+    public static final String COMPONENT_NAME = "ShardingSphere";
+    
+    /**
+     * The tag to record the bind variables of SQL.
+     */
+    public static final StringTag DB_BIND_VARIABLES = new 
StringTag("db.bind_vars");
+    
+    /**
+     * The tag to record the connection count.
+     */
+    public static final StringTag CONNECTION_COUNT = new 
StringTag("connection.count");
 }
diff --git a/shardingsphere-observability/shardingsphere-tracing/pom.xml 
b/shardingsphere-observability/shardingsphere-tracing/pom.xml
index 0fbc67a..68f6107 100644
--- a/shardingsphere-observability/shardingsphere-tracing/pom.xml
+++ b/shardingsphere-observability/shardingsphere-tracing/pom.xml
@@ -30,6 +30,5 @@
     <name>${project.artifactId}</name>
     
     <modules>
-        <module>shardingsphere-tracing-opentracing</module>
     </modules>
 </project>

Reply via email to