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);
}
}
}
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);
}
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);
}
}
}
Aggregations