You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2023/03/28 14:46:02 UTC

[skywalking-java] branch main updated: Support MySQL plugin tracing SQL parameters when useServerPrepStmts (#489)

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

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


The following commit(s) were added to refs/heads/main by this push:
     new 1f30e38864 Support MySQL plugin tracing SQL parameters when useServerPrepStmts (#489)
1f30e38864 is described below

commit 1f30e3886449b474056a21c4b479fa83726bcb93
Author: xu1009 <29...@qq.com>
AuthorDate: Tue Mar 28 22:45:55 2023 +0800

    Support MySQL plugin tracing SQL parameters when useServerPrepStmts (#489)
---
 CHANGES.md                                                           | 1 +
 .../jdbc/mysql/v5/define/PreparedStatementInstrumentation.java       | 5 +++--
 .../jdbc/mysql/v6/define/PreparedStatementInstrumentation.java       | 5 +++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index c4f27ee951..1497aab7ea 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -23,6 +23,7 @@ Release Notes.
 * Support keep trace profiling when cross-thread.
 * Fix unexpected whitespace of the command catalogs in several Redis plugins.
 * Fix a thread leak in `SamplingService` when updated sampling policy in the runtime.
+* Support MySQL plugin tracing SQL parameters when useServerPrepStmts 
 
 #### Documentation
 * Update docs of Tracing APIs, reorganize the API docs into six parts.
diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java
index 36a631fbe2..5eb42211bf 100644
--- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java
@@ -19,11 +19,11 @@
 package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define;
 
 import static net.bytebuddy.matcher.ElementMatchers.named;
-import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
 
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
 import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch;
 import org.apache.skywalking.apm.plugin.jdbc.mysql.Constants;
 
 import net.bytebuddy.description.method.MethodDescription;
@@ -38,6 +38,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati
 
     private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR;
     public static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement";
+    public static final String MYSQL_SERVER_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.ServerPreparedStatement";
 
     @Override
     public final ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
@@ -70,7 +71,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati
 
     @Override
     protected ClassMatch enhanceClass() {
-        return byName(MYSQL_PREPARED_STATEMENT_CLASS_NAME);
+        return MultiClassNameMatch.byMultiClassMatch(MYSQL_PREPARED_STATEMENT_CLASS_NAME, MYSQL_SERVER_PREPARED_STATEMENT_CLASS_NAME);
     }
 
 }
diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java
index 843071cd41..cd2b6a2650 100644
--- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java
@@ -23,9 +23,9 @@ import net.bytebuddy.matcher.ElementMatcher;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
 import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch;
 
 import static net.bytebuddy.matcher.ElementMatchers.named;
-import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
 
 /**
  * {@link PreparedStatementInstrumentation} define that the mysql-6.x plugin intercepts the following methods in the
@@ -36,6 +36,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati
 
     private static final String SERVICE_METHOD_INTERCEPTOR = org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR;
     public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement";
+    public static final String MYSQL6_SERVER_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement";
 
     @Override
     public final ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
@@ -68,7 +69,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati
 
     @Override
     protected ClassMatch enhanceClass() {
-        return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME);
+        return MultiClassNameMatch.byMultiClassMatch(MYSQL6_PREPARED_STATEMENT_CLASS_NAME, MYSQL6_SERVER_PREPARED_STATEMENT_CLASS_NAME);
     }
 
 }