Support ojdbc8 (#1571)

This commit is contained in:
Xin,Zhang 2018-08-22 17:43:57 +08:00 committed by 吴晟 Wu Sheng
parent 18d2d352fd
commit 1c8431c86f
6 changed files with 43 additions and 31 deletions

View File

@ -39,6 +39,7 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho
Class<?>[] argumentsTypes, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable { MethodInterceptResult result) throws Throwable {
StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField();
if (cacheObject != null && cacheObject.getConnectionInfo() != null) {
ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer());
@ -48,15 +49,18 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho
span.setComponent(connectInfo.getComponent()); span.setComponent(connectInfo.getComponent());
SpanLayer.asDB(span); SpanLayer.asDB(span);
} }
}
@Override @Override
public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Class<?>[] argumentsTypes,
Object ret) throws Throwable { Object ret) throws Throwable {
StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField();
if (cacheObject.getConnectionInfo() != null) {
if (cacheObject != null && cacheObject.getConnectionInfo() != null) {
ContextManager.stopSpan(); ContextManager.stopSpan();
} }
return ret; return ret;
} }

View File

@ -34,6 +34,7 @@ public class StatementExecuteMethodsInterceptor implements InstanceMethodsAround
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable { MethodInterceptResult result) throws Throwable {
StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField();
if (cacheObject != null && cacheObject.getConnectionInfo() != null) {
ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer());
@ -50,13 +51,14 @@ public class StatementExecuteMethodsInterceptor implements InstanceMethodsAround
SpanLayer.asDB(span); SpanLayer.asDB(span);
} }
}
@Override @Override
public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Class<?>[] argumentsTypes,
Object ret) throws Throwable { Object ret) throws Throwable {
StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField();
if (cacheObject.getConnectionInfo() != null) { if (cacheObject != null && cacheObject.getConnectionInfo() != null) {
ContextManager.stopSpan(); ContextManager.stopSpan();
} }
return ret; return ret;

View File

@ -24,7 +24,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 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.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch;
import org.apache.skywalking.apm.plugin.jdbc.define.Constants; import org.apache.skywalking.apm.plugin.jdbc.define.Constants;
import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.named;
@ -39,7 +39,6 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
* 3. Enhance <code>createStatement</code> by <code>org.apache.skywalking.apm.plugin.jdbc.oracle.CreateStatementInterceptor</code> * 3. Enhance <code>createStatement</code> by <code>org.apache.skywalking.apm.plugin.jdbc.oracle.CreateStatementInterceptor</code>
* 4. Enhance <code>commit, rollback, close, releaseSavepoint</code> by <code>org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor</code> * 4. Enhance <code>commit, rollback, close, releaseSavepoint</code> by <code>org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor</code>
* *
*
* @author zhangxin * @author zhangxin
*/ */
public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
@ -48,6 +47,7 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin
public static final String PREPARED_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.CreatePreparedStatementInterceptor"; 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 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"; public static final String CREATE_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.CreateStatementInterceptor";
public static final String T4C_CONNECTION_CLASS = "oracle.jdbc.driver.T4CConnection";
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0]; return new ConstructorInterceptPoint[0];
@ -111,6 +111,6 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin
} }
@Override protected ClassMatch enhanceClass() { @Override protected ClassMatch enhanceClass() {
return NameMatch.byName(ENHANCE_CLASS); return MultiClassNameMatch.byMultiClassMatch(ENHANCE_CLASS, T4C_CONNECTION_CLASS);
} }
} }

View File

@ -24,14 +24,16 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 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.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch;
import static net.bytebuddy.matcher.ElementMatchers.named; import static 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; import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.PREPARED_STATEMENT_INTERCEPT_CLASS;
public class OracleCallableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { public class OracleCallableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleCallableStatement"; public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleCallableStatement";
public static final String CALLABLE_STATEMENT_WRAPPER_CLASS = "oracle.jdbc.driver.OracleCallableStatementWrapper";
public static final String T4C_CALLABLE_STATMENT_CLASS = "oracle.jdbc.driver.T4CCallableStatement";
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0]; return new ConstructorInterceptPoint[0];
@ -58,6 +60,6 @@ public class OracleCallableInstrumentation extends ClassInstanceMethodsEnhancePl
} }
@Override protected ClassMatch enhanceClass() { @Override protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS); return MultiClassNameMatch.byMultiClassMatch(ENHANCE_CLASS, CALLABLE_STATEMENT_WRAPPER_CLASS, T4C_CALLABLE_STATMENT_CLASS);
} }
} }

View File

@ -24,14 +24,16 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 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.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch;
import static net.bytebuddy.matcher.ElementMatchers.named; import static 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; import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.PREPARED_STATEMENT_INTERCEPT_CLASS;
public class OraclePrepareStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { public class OraclePrepareStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OraclePreparedStatement"; public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OraclePreparedStatement";
public static final String PREPARED_STATEMENT_WRAPPER_CLASS = "oracle.jdbc.driver.OraclePreparedStatementWrapper";
public static final String T4C_PREPARED_STATEMENT_CLASS = "oracle.jdbc.driver.T4CPreparedStatement";
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0]; return new ConstructorInterceptPoint[0];
@ -59,6 +61,6 @@ public class OraclePrepareStatementInstrumentation extends ClassInstanceMethodsE
} }
@Override protected ClassMatch enhanceClass() { @Override protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS); return MultiClassNameMatch.byMultiClassMatch(ENHANCE_CLASS, PREPARED_STATEMENT_WRAPPER_CLASS, T4C_PREPARED_STATEMENT_CLASS);
} }
} }

View File

@ -24,14 +24,16 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; 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.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch;
import static net.bytebuddy.matcher.ElementMatchers.named; import static 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; import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.STATEMENT_INTERCEPT_CLASS;
public class OracleStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { public class OracleStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleStatement"; public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleStatement";
public static final String STATEMENT_WRAPPER_CLASS = "oracle.jdbc.driver.OracleStatementWrapper";
public static final String T4C_STATEMENT_CLASS = "oracle.jdbc.driver.T4CStatement";
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0]; return new ConstructorInterceptPoint[0];
@ -62,6 +64,6 @@ public class OracleStatementInstrumentation extends ClassInstanceMethodsEnhanceP
} }
@Override protected ClassMatch enhanceClass() { @Override protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS); return MultiClassNameMatch.byMultiClassMatch(ENHANCE_CLASS, STATEMENT_WRAPPER_CLASS, T4C_STATEMENT_CLASS);
} }
} }