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 2019/06/19 04:03:47 UTC
[skywalking] branch master updated: Add config to control tracing
sql parameters in MySQL agent (#2846)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 0956491 Add config to control tracing sql parameters in MySQL agent (#2846)
0956491 is described below
commit 09564919cb2837b1250e86b1a76430b90c70e377
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Wed Jun 19 12:03:38 2019 +0800
Add config to control tracing sql parameters in MySQL agent (#2846)
* Add config to control tracing sql parameters
---
.../skywalking/apm/agent/core/conf/Config.java | 15 +++
...reparedStatementIgnorableSetterInterceptor.java | 58 ++++++++++
...ntNullSetterInstanceMethodsInterceptPoint.java} | 40 +++----
...JDBCPreparedStatementNullSetterInterceptor.java | 57 ++++++++++
.../JDBCPreparedStatementSetterInterceptor.java | 58 ++++++++++
.../PSSetterDefinitionOfJDBCInstrumentation.java | 69 ++++++++++++
.../apm/plugin/jdbc/define/Constants.java | 40 +++++++
.../plugin/jdbc/define/StatementEnhanceInfos.java | 31 ++++++
...aredStatementIgnoredSetterInstrumentation.java} | 37 ++-----
.../define/PreparedStatementInstrumentation.java | 14 +--
...reparedStatementNullSetterInstrumentation.java} | 35 ++----
.../PreparedStatementSetterInstrumentation.java} | 35 ++----
.../src/main/resources/skywalking-plugin.def | 3 +
...aredStatementIgnoredSetterInstrumentation.java} | 35 ++----
.../define/PreparedStatementInstrumentation.java | 14 +--
...reparedStatementNullSetterInstrumentation.java} | 35 ++----
.../PreparedStatementSetterInstrumentation.java} | 35 ++----
.../src/main/resources/skywalking-plugin.def | 3 +
...aredStatementIgnoredSetterInstrumentation.java} | 35 ++----
.../define/PreparedStatementInstrumentation.java | 2 +-
...reparedStatementNullSetterInstrumentation.java} | 35 ++----
.../PreparedStatementSetterInstrumentation.java} | 35 ++----
.../src/main/resources/skywalking-plugin.def | 3 +
.../apm/plugin/jdbc/mysql/Constants.java | 4 +
...PreparedStatementExecuteMethodsInterceptor.java | 31 ++++++
.../skywalking/apm/plugin/ArbitrarySetTest.java | 118 +++++++++++++++++++++
docs/en/setup/service-agent/java-agent/README.md | 4 +-
27 files changed, 615 insertions(+), 266 deletions(-)
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
index 7784700..1c12100 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
@@ -194,6 +194,21 @@ public class Config {
public static boolean USE_QUALIFIED_NAME_AS_OPERATION_NAME = false;
}
+ public static class MySQL {
+ /**
+ * If set to true, the parameters of the sql (typically {@link java.sql.PreparedStatement})
+ * would be collected.
+ */
+ public static boolean TRACE_SQL_PARAMETERS = false;
+ /**
+ * For the sake of performance, SkyWalking won't save the entire parameters string into the tag,
+ * but only the first {@code SQL_PARAMETERS_MAX_LENGTH} characters.
+ *
+ * Set a negative number to save the complete parameter string to the tag.
+ */
+ public static int SQL_PARAMETERS_MAX_LENGTH = 512;
+ }
+
public static class SolrJ {
/**
* If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false.
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementIgnorableSetterInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementIgnorableSetterInterceptor.java
new file mode 100644
index 0000000..9294ad6
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementIgnorableSetterInterceptor.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.jdbc;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.plugin.jdbc.define.Constants;
+import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author kezhenxu94
+ */
+public class JDBCPreparedStatementIgnorableSetterInterceptor implements InstanceMethodsAroundInterceptor {
+ @Override
+ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class<?>[] argumentsTypes,
+ MethodInterceptResult result) throws Throwable {
+ final StatementEnhanceInfos statementEnhanceInfos = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
+ final int index = (Integer) allArguments[0];
+ statementEnhanceInfos.setParameter(index, Constants.SQL_PARAMETER_PLACEHOLDER);
+ }
+
+ @Override
+ public final Object afterMethod(EnhancedInstance objInst,
+ Method method,
+ Object[] allArguments,
+ Class<?>[] argumentsTypes,
+ Object ret) throws Throwable {
+ return ret;
+ }
+
+ @Override
+ public final void handleMethodException(EnhancedInstance objInst,
+ Method method,
+ Object[] allArguments,
+ Class<?>[] argumentsTypes,
+ Throwable t) {
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint.java
index c75a131..04e619e 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint.java
@@ -16,37 +16,31 @@
*
*/
+package org.apache.skywalking.apm.plugin.jdbc;
-package org.apache.skywalking.apm.plugin.jdbc.define;
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.define.Constants;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import static net.bytebuddy.matcher.ElementMatchers.named;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
-
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
+public final class JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint implements InstanceMethodsInterceptPoint {
+ @Override
+ public ElementMatcher<MethodDescription> getMethodsMatcher() {
+ return named("setNull");
}
- public String getSql() {
- return sql;
+ @Override
+ public String getMethodsInterceptor() {
+ return Constants.PREPARED_STATEMENT_NULL_SETTER_METHODS_INTERCEPTOR;
}
- public String getStatementName() {
- return statementName;
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
}
}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInterceptor.java
new file mode 100644
index 0000000..fe721f6
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInterceptor.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.jdbc;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author kezhenxu94
+ */
+public class JDBCPreparedStatementNullSetterInterceptor implements InstanceMethodsAroundInterceptor {
+ @Override
+ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class<?>[] argumentsTypes,
+ MethodInterceptResult result) throws Throwable {
+ final StatementEnhanceInfos statementEnhanceInfos = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
+ final int index = (Integer) allArguments[0];
+ statementEnhanceInfos.setParameter(index, "NULL");
+ }
+
+ @Override
+ public final Object afterMethod(EnhancedInstance objInst,
+ Method method,
+ Object[] allArguments,
+ Class<?>[] argumentsTypes,
+ Object ret) throws Throwable {
+ return ret;
+ }
+
+ @Override
+ public final void handleMethodException(EnhancedInstance objInst,
+ Method method,
+ Object[] allArguments,
+ Class<?>[] argumentsTypes,
+ Throwable t) {
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java
new file mode 100644
index 0000000..2fce632
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.jdbc;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author kezhenxu94
+ */
+public class JDBCPreparedStatementSetterInterceptor implements InstanceMethodsAroundInterceptor {
+ @Override
+ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class<?>[] argumentsTypes,
+ MethodInterceptResult result) throws Throwable {
+ final StatementEnhanceInfos statementEnhanceInfos = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
+ final int index = (Integer) allArguments[0];
+ final Object parameter = allArguments[1];
+ statementEnhanceInfos.setParameter(index, parameter);
+ }
+
+ @Override
+ public final Object afterMethod(EnhancedInstance objInst,
+ Method method,
+ Object[] allArguments,
+ Class<?>[] argumentsTypes,
+ Object ret) throws Throwable {
+ return ret;
+ }
+
+ @Override
+ public final void handleMethodException(EnhancedInstance objInst,
+ Method method,
+ Object[] allArguments,
+ Class<?>[] argumentsTypes,
+ Throwable t) {
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java
new file mode 100644
index 0000000..fb7a4c0
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.jdbc;
+
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import org.apache.skywalking.apm.agent.core.conf.Config;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.define.Constants;
+
+import java.util.Set;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.none;
+import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PS_IGNORABLE_SETTERS;
+import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PS_SETTERS;
+
+/**
+ * @author kezhenxu94
+ */
+public class PSSetterDefinitionOfJDBCInstrumentation implements InstanceMethodsInterceptPoint {
+ private final boolean ignorable;
+
+ public PSSetterDefinitionOfJDBCInstrumentation(boolean ignorable) {
+ this.ignorable = ignorable;
+ }
+
+ @Override
+ public ElementMatcher<MethodDescription> getMethodsMatcher() {
+ ElementMatcher.Junction<MethodDescription> matcher = none();
+
+ if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) {
+ final Set<String> setters = ignorable ? PS_IGNORABLE_SETTERS : PS_SETTERS;
+ for (String setter : setters) {
+ matcher = matcher.or(named(setter));
+ }
+ }
+
+ return matcher;
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return ignorable
+ ? Constants.PREPARED_STATEMENT_IGNORABLE_SETTER_METHODS_INTERCEPTOR
+ : Constants.PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java
index 895a5ca..03902cf 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java
@@ -19,6 +19,10 @@
package org.apache.skywalking.apm.plugin.jdbc.define;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
public class Constants {
public static final String CREATE_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.JDBCStatementInterceptor";
@@ -41,5 +45,41 @@ public class Constants {
public static final String CLOSE_METHOD_NAME = "close";
public static final String RELEASE_SAVE_POINT_METHOD_NAME = "releaseSavepoint";
+ public static final String SQL_PARAMETER_PLACEHOLDER = "?";
+ public static final Set<String> PS_SETTERS = new HashSet<String>(Arrays.asList(
+ "setArray",
+ "setBigDecimal",
+ "setBoolean",
+ "setByte",
+ "setDate",
+ "setDouble",
+ "setFloat",
+ "setInt",
+ "setLong",
+ "setNString",
+ "setObject",
+ "setRowId",
+ "setShort",
+ "setString",
+ "setTime",
+ "setTimestamp",
+ "setURL"
+ ));
+ public static final Set<String> PS_IGNORABLE_SETTERS = new HashSet<String>(Arrays.asList(
+ "setAsciiStream",
+ "setBinaryStream",
+ "setBlob",
+ "setBytes",
+ "setCharacterStream",
+ "setClob",
+ "setNCharacterStream",
+ "setNClob",
+ "setRef",
+ "setSQLXML",
+ "setUnicodeStream"
+ ));
+ public static final String PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInterceptor";
+ public static final String PREPARED_STATEMENT_NULL_SETTER_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInterceptor";
+ public static final String PREPARED_STATEMENT_IGNORABLE_SETTER_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementIgnorableSetterInterceptor";
}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
index c75a131..3ec22a4 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
@@ -21,6 +21,8 @@ package org.apache.skywalking.apm.plugin.jdbc.define;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import java.util.Arrays;
+
/**
* {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
* <code>sql</code> for trace mysql.
@@ -31,6 +33,8 @@ public class StatementEnhanceInfos {
private ConnectionInfo connectionInfo;
private String statementName;
private String sql;
+ private Object[] parameters;
+ private int maxIndex = 0;
public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
this.connectionInfo = connectionInfo;
@@ -49,4 +53,31 @@ public class StatementEnhanceInfos {
public String getStatementName() {
return statementName;
}
+
+ public void setParameter(int index, final Object parameter) {
+ maxIndex = maxIndex > index ? maxIndex : index;
+ index--; // start from 1
+ if (parameters == null) {
+ final int initialSize = Math.max(20, maxIndex);
+ parameters = new Object[initialSize];
+ Arrays.fill(parameters, null);
+ }
+ int length = parameters.length;
+ if (index >= length) {
+ int newSize = Math.max(index + 1, length * 2);
+ Object[] newParameters = new Object[newSize];
+ System.arraycopy(parameters, 0, newParameters, 0, length);
+ Arrays.fill(newParameters, length, newSize, null);
+ parameters = newParameters;
+ }
+ parameters[index] = parameter;
+ }
+
+ public Object[] getParameters() {
+ return parameters;
+ }
+
+ public int getMaxIndex() {
+ return maxIndex;
+ }
}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java
index c75a131..99f1c64 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java
@@ -17,36 +17,19 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.define;
+package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
-
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
- }
-
- public String getSql() {
- return sql;
- }
-
- public String getStatementName() {
- return statementName;
+public class PreparedStatementIgnoredSetterInstrumentation extends PreparedStatementInstrumentation {
+ @Override
+ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new PSSetterDefinitionOfJDBCInstrumentation(true)
+ };
}
}
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 77670ea..0837b46 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
@@ -31,13 +31,13 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMa
/**
* {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the
- * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and
+ * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and
* com.mysql.cj.jdbc.PreparedStatement class:
- * 1. execute
- * 2. executeQuery
- * 3. executeUpdate
- * 4. executeLargeUpdate
- * 5. addBatch
+ * 1. execute
+ * 2. executeQuery
+ * 3. executeUpdate
+ * 4. executeLargeUpdate
+ * 5. addBatch
*
* @author zhangxin
*/
@@ -51,7 +51,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati
return new ConstructorInterceptPoint[0];
}
- @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java
index c75a131..8e078b9 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java
@@ -17,36 +17,21 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.define;
+package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
+public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation {
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
+ @Override
+ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint()
+ };
}
- public String getSql() {
- return sql;
- }
-
- public String getStatementName() {
- return statementName;
- }
}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java
index c75a131..9acddbc 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java
@@ -17,36 +17,21 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.define;
+package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
+public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation {
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
+ @Override
+ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new PSSetterDefinitionOfJDBCInstrumentation(false)
+ };
}
- public String getSql() {
- return sql;
- }
-
- public String getStatementName() {
- return statementName;
- }
}
diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def
index a8350c9..57fea2c 100644
--- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def
+++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def
@@ -21,3 +21,6 @@ mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatemen
mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.StatementInstrumentation
mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.CacheIpsInstrumentation
mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.ConnectionImplCreateInstrumentation
+mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatementIgnoredSetterInstrumentation
+mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatementSetterInstrumentation
+mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatementNullSetterInstrumentation
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java
index c75a131..ea7d598 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java
@@ -17,36 +17,21 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.define;
+package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
+public class PreparedStatementIgnoredSetterInstrumentation extends PreparedStatementInstrumentation {
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
+ @Override
+ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new PSSetterDefinitionOfJDBCInstrumentation(true)
+ };
}
- public String getSql() {
- return sql;
- }
-
- public String getStatementName() {
- return statementName;
- }
}
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 89feca9..958c414 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
@@ -30,13 +30,13 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName
/**
* {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the
- * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and
+ * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and
* com.mysql.cj.jdbc.PreparedStatement class:
- * 1. execute
- * 2. executeQuery
- * 3. executeUpdate
- * 4. executeLargeUpdate
- * 5. addBatch
+ * 1. execute
+ * 2. executeQuery
+ * 3. executeUpdate
+ * 4. executeLargeUpdate
+ * 5. addBatch
*
* @author zhangxin
*/
@@ -49,7 +49,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati
return new ConstructorInterceptPoint[0];
}
- @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java
index c75a131..0238674 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java
@@ -17,36 +17,21 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.define;
+package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
+public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation {
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
+ @Override
+ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint()
+ };
}
- public String getSql() {
- return sql;
- }
-
- public String getStatementName() {
- return statementName;
- }
}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java
index c75a131..24778ca 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java
@@ -17,36 +17,21 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.define;
+package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
+public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation {
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
+ @Override
+ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new PSSetterDefinitionOfJDBCInstrumentation(false)
+ };
}
- public String getSql() {
- return sql;
- }
-
- public String getStatementName() {
- return statementName;
- }
}
diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def
index 087d2af..c5af17e 100644
--- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def
+++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def
@@ -21,3 +21,6 @@ mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatemen
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.StatementInstrumentation
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.CacheIpsInstrumentation
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.ConnectionImplCreateInstrumentation
+mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatementSetterInstrumentation
+mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatementIgnoredSetterInstrumentation
+mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatementNullSetterInstrumentation
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java
index c75a131..40dff47 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java
@@ -17,36 +17,21 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.define;
+package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
+public class PreparedStatementIgnoredSetterInstrumentation extends PreparedStatementInstrumentation {
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
+ @Override
+ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new PSSetterDefinitionOfJDBCInstrumentation(true)
+ };
}
- public String getSql() {
- return sql;
- }
-
- public String getStatementName() {
- return statementName;
- }
}
diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java
index 183c45d..180b0a0 100644
--- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java
@@ -40,7 +40,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati
return new ConstructorInterceptPoint[0];
}
- @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java
index c75a131..8f47621 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java
@@ -17,36 +17,21 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.define;
+package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
+public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation {
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
+ @Override
+ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint()
+ };
}
- public String getSql() {
- return sql;
- }
-
- public String getStatementName() {
- return statementName;
- }
}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java
similarity index 50%
copy from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
copy to apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java
index c75a131..12789f2 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java
@@ -17,36 +17,21 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.define;
+package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define;
-import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation;
/**
- * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and
- * <code>sql</code> for trace mysql.
- *
- * @author zhangxin
+ * @author kezhenxu94
*/
-public class StatementEnhanceInfos {
- private ConnectionInfo connectionInfo;
- private String statementName;
- private String sql;
-
- public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) {
- this.connectionInfo = connectionInfo;
- this.sql = sql;
- this.statementName = statementName;
- }
+public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation {
- public ConnectionInfo getConnectionInfo() {
- return connectionInfo;
+ @Override
+ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new PSSetterDefinitionOfJDBCInstrumentation(false)
+ };
}
- public String getSql() {
- return sql;
- }
-
- public String getStatementName() {
- return statementName;
- }
}
diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def
index 5a3c552f..11db6da 100644
--- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def
+++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def
@@ -19,3 +19,6 @@ mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.ConnectionInstru
mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.CallableInstrumentation
mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementInstrumentation
mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.StatementInstrumentation
+mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementSetterInstrumentation
+mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementNullSetterInstrumentation
+mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementIgnoredSetterInstrumentation
diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java
index a22c79b..80dcb14 100644
--- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java
@@ -18,6 +18,8 @@
package org.apache.skywalking.apm.plugin.jdbc.mysql;
+import org.apache.skywalking.apm.agent.core.context.tag.StringTag;
+
/**
* @author: dingshaocheng
*/
@@ -29,4 +31,6 @@ public class Constants {
public static final String SET_CATALOG_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.SetCatalogInterceptor";
public static final String STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor";
public static final String DRIVER_CONNECT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.DriverConnectInterceptor";
+
+ public static final StringTag SQL_PARAMETERS = new StringTag("db.sql.parameters");
}
diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java
index 5af6e98..732816c 100644
--- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java
@@ -18,6 +18,7 @@
package org.apache.skywalking.apm.plugin.jdbc.mysql;
+import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
@@ -30,6 +31,8 @@ import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
import java.lang.reflect.Method;
+import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETERS;
+
public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor {
@Override
@@ -52,6 +55,19 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho
Tags.DB_STATEMENT.set(span, cacheObject.getSql());
span.setComponent(connectInfo.getComponent());
+ if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) {
+ final Object[] parameters = cacheObject.getParameters();
+ if (parameters != null && parameters.length > 0) {
+ int maxIndex = cacheObject.getMaxIndex();
+ String parameterString = buildParameterString(parameters, maxIndex);
+ int sqlParametersMaxLength = Config.Plugin.MySQL.SQL_PARAMETERS_MAX_LENGTH;
+ if (sqlParametersMaxLength > 0 && parameterString.length() > sqlParametersMaxLength) {
+ parameterString = parameterString.substring(0, sqlParametersMaxLength) + "...";
+ }
+ SQL_PARAMETERS.set(span, parameterString);
+ }
+ }
+
SpanLayer.asDB(span);
}
}
@@ -78,4 +94,19 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho
private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) {
return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName;
}
+
+ private String buildParameterString(Object[] parameters, int maxIndex) {
+ String parameterString = "[";
+ boolean first = true;
+ for (int i = 0; i < maxIndex; i++) {
+ Object parameter = parameters[i];
+ if (!first) {
+ parameterString += ",";
+ }
+ parameterString += parameter;
+ first = false;
+ }
+ parameterString += "]";
+ return parameterString;
+ }
}
diff --git a/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java
new file mode 100644
index 0000000..36a585a
--- /dev/null
+++ b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Benchmark Mode Cnt Score Error Units
+ * ArbitrarySetTest.array thrpt 10 2360.500 ± 138.279 ops/ms
+ * ArbitrarySetTest.arrayList thrpt 10 1080.005 ± 225.897 ops/ms
+ * ArbitrarySetTest.linkedList thrpt 10 188.007 ± 11.739 ops/ms
+ * ArbitrarySetTest.treeMap thrpt 10 214.384 ± 27.816 ops/ms
+ *
+ * @author kezhenxu94
+ */
+@BenchmarkMode(Mode.Throughput)
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Thread)
+@Fork(2)
+@Warmup(iterations = 4)
+@Measurement(iterations = 5)
+public class ArbitrarySetTest {
+ private static final Object PLACEHOLDER = new Object();
+
+ @Benchmark
+ public void arrayList() {
+ ArrayList<Object> list = new ArrayList<Object>(Collections.nCopies(20, PLACEHOLDER));
+ for (int i = 0; i < 100; i++) {
+ int oldSize = list.size();
+ if (i >= oldSize) {
+ int newSize = Math.max(oldSize * 2, i);
+ list.addAll(oldSize, Collections.nCopies(newSize - oldSize, PLACEHOLDER));
+ }
+ list.set(i, i);
+ }
+ }
+
+ @Benchmark
+ public void linkedList() {
+ LinkedList<Object> list = new LinkedList<Object>(Collections.nCopies(20, PLACEHOLDER));
+ for (int i = 0; i < 100; i++) {
+ int oldSize = list.size();
+ if (i >= oldSize) {
+ int newSize = Math.max(oldSize * 2, i);
+ list.addAll(oldSize, Collections.nCopies(newSize - oldSize, PLACEHOLDER));
+ }
+ list.set(i, i);
+ }
+ }
+
+ @Benchmark
+ public void array() {
+ Object[] array = new Object[20];
+ Arrays.fill(array, PLACEHOLDER);
+ for (int i = 1; i <= 100; i++) {
+ int length = array.length;
+ if (i >= length) {
+ int newSize = Math.max(i, length * 2);
+ Object[] newArray = new Object[newSize];
+ System.arraycopy(array, 0, newArray, 0, length);
+ Arrays.fill(newArray, length, newSize, PLACEHOLDER);
+ array = newArray;
+ }
+ array[i] = i;
+ }
+ }
+
+ @Benchmark
+ public void treeMap() {
+ final Map<Integer, Object> treeMap = new TreeMap<Integer, Object>();
+ for (int i = 0; i < 100; i++) {
+ treeMap.put(i, i);
+ }
+ }
+
+ @BenchmarkMode(Mode.AverageTime)
+ @OutputTimeUnit(TimeUnit.MICROSECONDS)
+ public static void main(String[] args) throws RunnerException {
+ Options options = new OptionsBuilder().include(ArbitrarySetTest.class.getSimpleName()).build();
+ new Runner(options).run();
+ }
+}
diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md
index 9b727d5..2d18851 100644
--- a/docs/en/setup/service-agent/java-agent/README.md
+++ b/docs/en/setup/service-agent/java-agent/README.md
@@ -82,11 +82,13 @@ property key | Description | Default |
`plugin.elasticsearch.trace_dsl`|If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false.|`false`|
`plugin.springmvc.use_qualified_name_as_endpoint_name`|If true, the fully qualified method name will be used as the endpoint name instead of the request URL, default is false.|`false`|
`plugin.toolit.use_qualified_name_as_operation_name`|If true, the fully qualified method name will be used as the operation name instead of the given operation name, default is false.|`false`|
+`plugin.mysql.trace_sql_parameters`|If set to true, the parameters of the sql (typically `java.sql.PreparedStatement`) would be collected.|`false`|
+`plugin.mysql.sql_parameters_max_length`|If set to positive number, the `db.sql.parameters` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem.|`512`|
`plugin.solrj.trace_statement`|If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false.|`false`|
`plugin.solrj.trace_ops_params`|If true, trace all the operation parameters in Solr request, default is false.|`false`|
## Optional Plugins
-Java agent plugins are all pluggable. Optional plugins could be provided in `optional-plugins` folder under agent or 3rd party repositores.
+Java agent plugins are all pluggable. Optional plugins could be provided in `optional-plugins` folder under agent or 3rd party repositories.
For using these plugins, you need to put the target plugin jar file into `/plugins`.
Now, we have the following known optional plugins.