use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.
the class CassandraDriverConnectInterceptor method prepareAfterTrace.
@Override
protected void prepareAfterTrace(Object target, Object[] args, Object result, Throwable throwable) {
final boolean success = InterceptorUtils.isSuccess(throwable);
// Must not check if current transaction is trace target or not. Connection can be made by other thread.
List<String> hostList = new ArrayList<String>();
if (target instanceof Cluster) {
Cluster cluster = (Cluster) target;
final Set<Host> hosts = cluster.getMetadata().getAllHosts();
final int port = cluster.getConfiguration().getProtocolOptions().getPort();
for (Host host : hosts) {
final String hostAddress = host.getAddress().getHostAddress() + ":" + port;
hostList.add(hostAddress);
}
}
if (args == null) {
return;
}
final String keyspace = (String) args[0];
DatabaseInfo databaseInfo = createDatabaseInfo(keyspace, hostList);
if (success) {
if (recordConnection) {
if (result instanceof DatabaseInfoAccessor) {
((DatabaseInfoAccessor) result)._$PINPOINT$_setDatabaseInfo(databaseInfo);
}
}
}
}
use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.
the class CassandraDriverConnectInterceptor method doInAfterTrace.
@Override
protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
if (recordConnection) {
DatabaseInfo databaseInfo;
if (result instanceof DatabaseInfoAccessor) {
databaseInfo = ((DatabaseInfoAccessor) result)._$PINPOINT$_getDatabaseInfo();
} else {
databaseInfo = null;
}
if (databaseInfo == null) {
databaseInfo = UnKnownDatabaseInfo.INSTANCE;
}
// Count database connect too because it's very heavy operation
recorder.recordServiceType(databaseInfo.getType());
recorder.recordEndPoint(databaseInfo.getMultipleHost());
recorder.recordDestinationId(databaseInfo.getDatabaseId());
}
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
}
use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.
the class CassandraPreparedStatementCreateInterceptor method doInBeforeTrace.
@Override
public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
DatabaseInfo databaseInfo = (target instanceof DatabaseInfoAccessor) ? ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo() : null;
if (databaseInfo == null) {
databaseInfo = UnKnownDatabaseInfo.INSTANCE;
}
recorder.recordServiceType(databaseInfo.getType());
recorder.recordEndPoint(databaseInfo.getMultipleHost());
recorder.recordDestinationId(databaseInfo.getDatabaseId());
}
use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.
the class MySQLConnectionCreateInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args, result, throwable);
}
if (args == null || args.length != 5) {
return;
}
final String hostToConnectTo = getString(args[0]);
final Integer portToConnectTo = getInteger(args[1]);
final String databaseId = getString(args[3]);
// In case of loadbalance, connectUrl is modified.
// final String url = getString(args[4]);
DatabaseInfo databaseInfo = null;
if (hostToConnectTo != null && portToConnectTo != null && databaseId != null) {
// It's dangerous to use this url directly
databaseInfo = createDatabaseInfo(hostToConnectTo, portToConnectTo, databaseId);
if (InterceptorUtils.isSuccess(throwable)) {
// Set only if connection is success.
if (target instanceof DatabaseInfoAccessor) {
((DatabaseInfoAccessor) target)._$PINPOINT$_setDatabaseInfo(databaseInfo);
}
}
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
// We must do this if current transaction is being recorded.
if (databaseInfo != null) {
recorder.recordServiceType(databaseInfo.getType());
recorder.recordEndPoint(databaseInfo.getMultipleHost());
recorder.recordDestinationId(databaseInfo.getDatabaseId());
}
}
use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.
the class DriverConnectInterceptorTest method driverConnect.
@Test
public void driverConnect() throws SQLException {
TraceContext traceContext = mock(TraceContext.class);
MethodDescriptor methodDescriptor = mock(MethodDescriptor.class);
JdbcUrlParser parser = mock(JdbcUrlParser.class);
when(parser.parse(anyString())).thenReturn(UnKnownDatabaseInfo.INSTANCE);
String invalidJdbcUrl = "invalidUrl";
Driver driver = mock(Driver.class);
DatabaseInfoAccessor setAccessor = mock(DatabaseInfoAccessor.class);
DatabaseInfoAccessor getAccessor = mock(DatabaseInfoAccessor.class);
SpanEventRecorder spanEventRecorder = mock(SpanEventRecorder.class);
DriverConnectInterceptor driverConnectInterceptor = new DriverConnectInterceptor(traceContext, methodDescriptor, parser);
driverConnectInterceptor.prepareAfterTrace(driver, va(invalidJdbcUrl), setAccessor, null);
driverConnectInterceptor.doInAfterTrace(spanEventRecorder, driver, va(invalidJdbcUrl), getAccessor, null);
verify(setAccessor, times(1))._$PINPOINT$_setDatabaseInfo(UnKnownDatabaseInfo.INSTANCE);
verify(getAccessor, times(1))._$PINPOINT$_getDatabaseInfo();
}
Aggregations