From 7554cfabaf75ba983549056a5830a39f7f8bd246 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 30 Jan 2018 20:50:17 +0800 Subject: [PATCH] [Agent] Change the enhance way of oracle plugin --- .../apm/plugin/jdbc/oracle/Constants.java | 30 ++++++++ .../oracle/CreateCallableInterceptor.java} | 31 ++------ .../CreatePreparedStatementInterceptor.java | 47 ++++++++++++ .../oracle/CreateStatementInterceptor.java | 47 ++++++++++++ ...redStatementExecuteMethodsInterceptor.java | 74 ++++++++++++++++++ .../StatementExecuteMethodsInterceptor.java | 76 +++++++++++++++++++ .../define/ConnectionInstrumentation.java | 63 ++++----------- .../define/OracleCallableInstrumentation.java | 70 +++++++++++++++++ ...OraclePrepareStatementInstrumentation.java | 71 +++++++++++++++++ .../OracleStatementInstrumentation.java | 74 ++++++++++++++++++ .../src/main/resources/skywalking-plugin.def | 3 + 11 files changed, 513 insertions(+), 73 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/Constants.java rename apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/{oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java => org/apache/skywalking/apm/plugin/jdbc/oracle/CreateCallableInterceptor.java} (55%) create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreatePreparedStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/PreparedStatementExecuteMethodsInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/StatementExecuteMethodsInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleCallableInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OraclePrepareStatementInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleStatementInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/Constants.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/Constants.java new file mode 100644 index 0000000000..3a4e72de08 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/Constants.java @@ -0,0 +1,30 @@ +/* + * 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.oracle; + +/** + * Constants variables + * + * @author zhang xin + */ +public final class Constants { + public static final String STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor"; + + public static final String PREPARED_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.PreparedStatementExecuteMethodsInterceptor"; +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateCallableInterceptor.java similarity index 55% rename from apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java rename to apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateCallableInterceptor.java index 06ccae6d64..d526ac5063 100644 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateCallableInterceptor.java @@ -16,26 +16,16 @@ * */ -package oracle.jdbc.driver; +package org.apache.skywalking.apm.plugin.jdbc.oracle; import java.lang.reflect.Method; -import java.sql.Connection; -import java.sql.PreparedStatement; 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 org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; -/** - * {@link JDBCPrepareStatementWithArrayInterceptor} return {@link SWPreparedStatement} instance that wrapper the real - * preparedStatement instance when the client call oracle.jdbc.driver.PhysicalConnection#prepareStatement(String, - * int[]) method or oracle.jdbc.driver.PhysicalConnection#prepareStatement(String, String[]) - * method. - * - * @author zhangxin - */ -public class JDBCPrepareStatementWithArrayInterceptor implements InstanceMethodsAroundInterceptor { +public class CreateCallableInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { @@ -45,19 +35,10 @@ public class JDBCPrepareStatementWithArrayInterceptor implements InstanceMethods @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { - /** - * To prevent the org.postgresql.jdbc.prepareStatement(String sql) method from repeating - * interceptor, Because PGConnection call org.postgresql.jdbc.prepareStatement(String sql) method when - * the second argument is empty. - * - * @see oracle.jdbc.driver.PhysicalConnection#prepareStatement(String, int[]) - * @see oracle.jdbc.driver.PhysicalConnection#prepareStatement(String, String[]) - **/ - String sql = (String)allArguments[0]; - if (!AutoKeyInfo.isInsertSqlStmt(sql)) { - return ret; + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "CallableStatement")); } - return new SWPreparedStatement((Connection)objInst, (PreparedStatement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0]); + return ret; } @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreatePreparedStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreatePreparedStatementInterceptor.java new file mode 100644 index 0000000000..9c8a2ba3b6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreatePreparedStatementInterceptor.java @@ -0,0 +1,47 @@ +/* + * 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.oracle; + +import java.lang.reflect.Method; +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 org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +public class CreatePreparedStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "PreparedStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateStatementInterceptor.java new file mode 100644 index 0000000000..ea2b95cade --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateStatementInterceptor.java @@ -0,0 +1,47 @@ +/* + * 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.oracle; + +import java.lang.reflect.Method; +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 org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +public class CreateStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), "", "Statement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/PreparedStatementExecuteMethodsInterceptor.java new file mode 100644 index 0000000000..0653339319 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/PreparedStatementExecuteMethodsInterceptor.java @@ -0,0 +1,74 @@ +/* + * 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.oracle; + +import java.lang.reflect.Method; +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; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +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 org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * @author zhang xin + */ +public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, cacheObject.getSql()); + span.setComponent(connectInfo.getComponent()); + SpanLayer.asDB(span); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } + + private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { + return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/StatementExecuteMethodsInterceptor.java new file mode 100644 index 0000000000..df6668e39c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/StatementExecuteMethodsInterceptor.java @@ -0,0 +1,76 @@ +/* + * 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.oracle; + +import java.lang.reflect.Method; +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; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +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 org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +public class StatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + + String sql = ""; + if (allArguments.length > 0) { + sql = (String)allArguments[0]; + } + + Tags.DB_STATEMENT.set(span, sql); + span.setComponent(connectInfo.getComponent()); + + SpanLayer.asDB(span); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } + + private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { + return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java index 7533ae68d7..f4542100fd 100644 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java @@ -16,12 +16,10 @@ * */ - package org.apache.skywalking.apm.plugin.jdbc.oracle.define; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch; 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.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; @@ -33,28 +31,23 @@ import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; /** - * {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link - * oracle.jdbc.driver.PhysicalConnection}.
- * - * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor - * 2. Enhance prepareStatement that the seconds argument type is java.lang.String[] by - * oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor - * 3. Enhance prepareStatement that the seconds argument type is int[] by - * oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor - * 4. Enhance prepareCall by - * org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor - * 5. Enhance createStatement - * by org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor - * 6. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor + * {@link ConnectionInstrumentation} define that the oracle plugin intercept the following methods that the class which + * extend {@link oracle.jdbc.driver.PhysicalConnection}.
+ *
+ * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.oracle.CreatePreparedStatementInterceptor
+ * 2. Enhance prepareCall by org.apache.skywalking.apm.plugin.jdbc.oracle.CreateCallableInterceptor
+ * 3. Enhance createStatement by org.apache.skywalking.apm.plugin.jdbc.oracle.CreateStatementInterceptor
+ * 4. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor
+ * 
* * @author zhangxin */ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS = "oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor"; public static final String ENHANCE_CLASS = "oracle.jdbc.driver.PhysicalConnection"; - public static final String STRING_ARRAY_ARGUMENT_TYPE = "java.lang.String[]"; - public static final String INT_ARRAY_ARGUMENT_TYPE = "int[]"; + public static final String PREPARED_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.CreatePreparedStatementInterceptor"; + public static final String CALLABLE_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.CreateCallableInterceptor"; + public static final String CREATE_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.CreateStatementInterceptor"; @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[0]; @@ -64,37 +57,11 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(3)); - } - - @Override public String getMethodsInterceptor() { - return Constants.PREPARE_STATEMENT_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(ArgumentTypeNameMatch.takesArgumentWithType(1, STRING_ARRAY_ARGUMENT_TYPE)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(ArgumentTypeNameMatch.takesArgumentWithType(1, INT_ARRAY_ARGUMENT_TYPE)); + return named(Constants.PREPARE_STATEMENT_METHOD_NAME); } @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS; + return PREPARED_STATEMENT_INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { @@ -107,7 +74,7 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override public String getMethodsInterceptor() { - return Constants.PREPARE_CALL_INTERCEPT_CLASS; + return CALLABLE_INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { @@ -120,7 +87,7 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override public String getMethodsInterceptor() { - return Constants.CREATE_STATEMENT_INTERCEPT_CLASS; + return CREATE_STATEMENT_INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleCallableInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleCallableInstrumentation.java new file mode 100644 index 0000000000..1d0be4a5ea --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleCallableInstrumentation.java @@ -0,0 +1,70 @@ +/* + * 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.oracle.define; + +import net.bytebuddy.description.method.MethodDescription; +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.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.PREPARED_STATEMENT_INTERCEPT_CLASS; + +/** + * {@link OracleCallableInstrumentation} define that the oracle plugin intercept the execute, executeQuery and + * executeUpdate method in {@link oracle.jdbc.driver.OracleCallableStatement} class by ${@link + * org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor} + * + * @author zhangxin + */ +public class OracleCallableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleCallableStatement"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")); + } + + @Override public String getMethodsInterceptor() { + return PREPARED_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OraclePrepareStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OraclePrepareStatementInstrumentation.java new file mode 100644 index 0000000000..093ded3eb6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OraclePrepareStatementInstrumentation.java @@ -0,0 +1,71 @@ +/* + * 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.oracle.define; + +import net.bytebuddy.description.method.MethodDescription; +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.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.PREPARED_STATEMENT_INTERCEPT_CLASS; + +/** + * {@link OraclePrepareStatementInstrumentation} define that the oracle plugin intercept the execute, + * executeQuery, executeUpdate and executeLargeUpdate method in {@link oracle.jdbc.driver.OraclePreparedStatement} + * class by ${@link org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor} + * + * @author zhangxin + */ +public class OraclePrepareStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OraclePreparedStatement"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")); + } + + @Override public String getMethodsInterceptor() { + return PREPARED_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleStatementInstrumentation.java new file mode 100644 index 0000000000..94c15f2c74 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleStatementInstrumentation.java @@ -0,0 +1,74 @@ +/* + * 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.oracle.define; + +import net.bytebuddy.description.method.MethodDescription; +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.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.STATEMENT_INTERCEPT_CLASS; + +/** + * {@link OracleStatementInstrumentation} define that the oracle plugin intercept the execute, executeQuery, + * executeUpdate and executeLargeUpdate method in {@link oracle.jdbc.driver.OracleStatement} class by ${@link + * org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor} + * + * @author zhangxin + */ +public class OracleStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleStatement"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")) + .or(named("executeBatchInternal")) + .or(named("executeUpdateInternal")) + .or(named("executeQuery")); + } + + @Override public String getMethodsInterceptor() { + return STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def index 3a3b19358f..8b6dd1307c 100644 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,5 @@ oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.DriverInstrumentation oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.ConnectionInstrumentation +oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.OracleCallableInstrumentation +oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.OraclePrepareStatementInstrumentation +oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.OracleStatementInstrumentation -- GitLab