Search in sources :

Example 11 with ConnectionInfo

use of org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo in project incubator-skywalking by apache.

the class PreparedStatementExecuteMethodsInterceptor method beforeMethod.

@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);
}
Also used : ConnectionInfo(org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo) StatementEnhanceInfos(org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 12 with ConnectionInfo

use of org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo in project incubator-skywalking by apache.

the class StatementExecuteMethodsInterceptor method beforeMethod.

@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();
    /**
     * To protected the code occur NullPointException. because mysql execute system sql when constructor method in
     * {@link com.mysql.jdbc.ConnectionImpl} class executed. but the interceptor set the connection Info after
     * the constructor method executed.
     *
     * @see JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object)
     */
    if (connectInfo != null) {
        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());
        /**
         * The first argument of all intercept method in `com.mysql.jdbc.StatementImpl` class is SQL, except the
         * `executeBatch` method that the jdbc plugin need to trace, because of this method argument size is zero.
         */
        String sql = "";
        if (allArguments.length > 0) {
            sql = (String) allArguments[0];
        }
        Tags.DB_STATEMENT.set(span, sql);
        span.setComponent(connectInfo.getComponent());
        SpanLayer.asDB(span);
    }
}
Also used : ConnectionInfo(org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo) StatementEnhanceInfos(org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 13 with ConnectionInfo

use of org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo in project incubator-skywalking by apache.

the class PreparedStatementExecuteMethodsInterceptor method beforeMethod.

@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);
}
Also used : ConnectionInfo(org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo) StatementEnhanceInfos(org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 14 with ConnectionInfo

use of org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo in project incubator-skywalking by apache.

the class StatementExecuteMethodsInterceptor method beforeMethod.

@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, (String) allArguments[0]);
    span.setComponent(connectInfo.getComponent());
    SpanLayer.asDB(span);
}
Also used : ConnectionInfo(org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo) StatementEnhanceInfos(org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 15 with ConnectionInfo

use of org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo in project incubator-skywalking by apache.

the class StatementExecuteMethodsInterceptor method beforeMethod.

@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);
}
Also used : ConnectionInfo(org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo) StatementEnhanceInfos(org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

ConnectionInfo (org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo)21 Test (org.junit.Test)14 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)7 StatementEnhanceInfos (org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos)6