From 1f30e3886449b474056a21c4b479fa83726bcb93 Mon Sep 17 00:00:00 2001 From: xu1009 <2933250475@qq.com> Date: Tue, 28 Mar 2023 22:45:55 +0800 Subject: [PATCH] Support MySQL plugin tracing SQL parameters when useServerPrepStmts (#489) --- CHANGES.md | 1 + .../mysql/v5/define/PreparedStatementInstrumentation.java | 5 +++-- .../mysql/v6/define/PreparedStatementInstrumentation.java | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c4f27ee95..1497aab7e 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 36a631fbe..5eb42211b 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 843071cd4..cd2b6a265 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); } }