Search in sources :

Example 1 with BindValueAccessor

use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor in project pinpoint by naver.

the class PreparedStatementExecuteQueryInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        DatabaseInfo databaseInfo = (target instanceof DatabaseInfoAccessor) ? ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo() : null;
        if (databaseInfo == null) {
            databaseInfo = UnKnownDatabaseInfo.INSTANCE;
        }
        recorder.recordServiceType(databaseInfo.getExecuteQueryType());
        recorder.recordEndPoint(databaseInfo.getMultipleHost());
        recorder.recordDestinationId(databaseInfo.getDatabaseId());
        ParsingResult parsingResult = null;
        if (target instanceof ParsingResultAccessor) {
            parsingResult = ((ParsingResultAccessor) target)._$PINPOINT$_getParsingResult();
        }
        Map<Integer, String> bindValue = null;
        if (target instanceof BindValueAccessor) {
            bindValue = ((BindValueAccessor) target)._$PINPOINT$_getBindValue();
        }
        if (bindValue != null) {
            String bindString = toBindVariable(bindValue);
            recorder.recordSqlParsingResult(parsingResult, bindString);
        } else {
            recorder.recordSqlParsingResult(parsingResult);
        }
        recorder.recordApi(descriptor);
        //            trace.recordApi(apiId);
        // Need to change where to invoke clean().
        // There is cleanParameters method but it's not necessary to intercept that method.
        // iBatis intentionally does not invoke it in most cases. 
        clean(target);
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn(e.getMessage(), e);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) BindValueAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)

Example 2 with BindValueAccessor

use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor in project pinpoint by naver.

the class PreparedStatementBindVariableInterceptor method after.

@Override
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, className, methodName, parameterDescription, args, result, throwable);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    if (!(target instanceof BindValueAccessor)) {
        return;
    }
    final Integer index = NumberUtils.toInteger(args[0]);
    if (index == null) {
        // something is wrong
        return;
    }
    Map<Integer, String> bindList = ((BindValueAccessor) target)._$PINPOINT$_getBindValue();
    if (bindList == null) {
        bindList = new HashMap<Integer, String>();
        ((BindValueAccessor) target)._$PINPOINT$_setBindValue(bindList);
    }
    final String value = BindValueConverter.convert(methodName, args);
    bindList.put(index, value);
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) BindValueAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor)

Example 3 with BindValueAccessor

use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor in project pinpoint by naver.

the class CassandraStatementExecuteQueryInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        DatabaseInfo databaseInfo = (target instanceof DatabaseInfoAccessor) ? ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo() : null;
        if (databaseInfo == null) {
            databaseInfo = UnKnownDatabaseInfo.INSTANCE;
        }
        recorder.recordServiceType(databaseInfo.getExecuteQueryType());
        recorder.recordEndPoint(databaseInfo.getMultipleHost());
        recorder.recordDestinationId(databaseInfo.getDatabaseId());
        String sql;
        if (args[0] instanceof BoundStatement) {
            sql = ((BoundStatement) args[0]).preparedStatement().getQueryString();
        } else if (args[0] instanceof RegularStatement) {
            sql = ((RegularStatement) args[0]).getQueryString();
        } else {
            // we have string
            sql = (String) args[0];
        }
        ParsingResult parsingResult = traceContext.parseSql(sql);
        if (parsingResult != null) {
            ((ParsingResultAccessor) target)._$PINPOINT$_setParsingResult(parsingResult);
        } else {
            if (logger.isErrorEnabled()) {
                logger.error("sqlParsing fail. parsingResult is null sql:{}", sql);
            }
        }
        Map<Integer, String> bindValue = ((BindValueAccessor) target)._$PINPOINT$_getBindValue();
        // Extracting bind variables from already-serialized is too risky
        if (bindValue != null && !bindValue.isEmpty()) {
            String bindString = toBindVariable(bindValue);
            recorder.recordSqlParsingResult(parsingResult, bindString);
        } else {
            recorder.recordSqlParsingResult(parsingResult);
        }
        recorder.recordApi(descriptor);
        clean(target);
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn(e.getMessage(), e);
        }
    }
}
Also used : UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) BindValueAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor) RegularStatement(com.datastax.driver.core.RegularStatement) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) BoundStatement(com.datastax.driver.core.BoundStatement)

Aggregations

Trace (com.navercorp.pinpoint.bootstrap.context.Trace)3 BindValueAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor)3 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)2 ParsingResult (com.navercorp.pinpoint.bootstrap.context.ParsingResult)2 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)2 DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)2 ParsingResultAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)2 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 RegularStatement (com.datastax.driver.core.RegularStatement)1