mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-25 04:35:59 +10:00
[강운덕] [LUCYSUS-1744] jdbc 인터셉터 보완
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@837 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
+32
-32
@@ -12,50 +12,50 @@ import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
|
||||
/**
|
||||
* Method interceptor
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* org.apache.http.impl.client.AbstractHttpClient.
|
||||
* public <T> T execute(
|
||||
* final HttpHost target,
|
||||
* final HttpHost target,
|
||||
* final HttpRequest request,
|
||||
* final ResponseHandler<? extends T> responseHandler,
|
||||
* final HttpContext context)
|
||||
* final ResponseHandler<? extends T> responseHandler,
|
||||
* final HttpContext context)
|
||||
* throws IOException, ClientProtocolException {
|
||||
* </pre>
|
||||
*/
|
||||
public class ExecuteMethodInterceptor implements StaticAroundInterceptor {
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
final HttpHost host = (HttpHost) args[0];
|
||||
final HttpRequest request = (HttpRequest) args[1];
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
final HttpHost host = (HttpHost) args[0];
|
||||
final HttpRequest request = (HttpRequest) args[1];
|
||||
|
||||
try {
|
||||
Trace.traceBlockBegin();
|
||||
TraceID nextId = Trace.getNextTraceId();
|
||||
try {
|
||||
Trace.traceBlockBegin();
|
||||
TraceID nextId = Trace.getNextTraceId();
|
||||
|
||||
// UUID format을 그대로.
|
||||
request.addHeader(Header.HTTP_TRACE_ID.toString(), nextId.getId().toString());
|
||||
request.addHeader(Header.HTTP_SPAN_ID.toString(), Long.toString(nextId.getSpanId()));
|
||||
request.addHeader(Header.HTTP_PARENT_SPAN_ID.toString(), Long.toString(nextId.getParentSpanId()));
|
||||
request.addHeader(Header.HTTP_SAMPLED.toString(), String.valueOf(nextId.isSampled()));
|
||||
request.addHeader(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
|
||||
// UUID format을 그대로.
|
||||
request.addHeader(Header.HTTP_TRACE_ID.toString(), nextId.getId().toString());
|
||||
request.addHeader(Header.HTTP_SPAN_ID.toString(), Long.toString(nextId.getSpanId()));
|
||||
request.addHeader(Header.HTTP_PARENT_SPAN_ID.toString(), Long.toString(nextId.getParentSpanId()));
|
||||
request.addHeader(Header.HTTP_SAMPLED.toString(), String.valueOf(nextId.isSampled()));
|
||||
request.addHeader(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
|
||||
|
||||
Trace.recordRpcName(request.getProtocolVersion().toString(), "CLIENT");
|
||||
Trace.recordEndPoint(request.getProtocolVersion().toString() + ":" + host.getHostName() + ":" + host.getPort());
|
||||
Trace.recordAttibute("http.url", request.getRequestLine().getUri());
|
||||
Trace.record(Annotation.ClientSend);
|
||||
} finally {
|
||||
Trace.traceBlockEnd();
|
||||
}
|
||||
Trace.recordRpcName(request.getProtocolVersion().toString(), "CLIENT");
|
||||
Trace.recordEndPoint(request.getProtocolVersion().toString() + ":" + host.getHostName() + ":" + host.getPort());
|
||||
Trace.recordAttibute("http.url", request.getRequestLine().getUri());
|
||||
Trace.record(Annotation.ClientSend);
|
||||
} finally {
|
||||
Trace.traceBlockEnd();
|
||||
}
|
||||
|
||||
StopWatch.start("ExecuteMethodInterceptor");
|
||||
}
|
||||
StopWatch.start("ExecuteMethodInterceptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) {
|
||||
Trace.traceBlockBegin();
|
||||
Trace.record(Annotation.ClientRecv, StopWatch.stopAndGetElapsed("ExecuteMethodInterceptor"));
|
||||
Trace.traceBlockEnd();
|
||||
}
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) {
|
||||
Trace.traceBlockBegin();
|
||||
Trace.record(Annotation.ClientRecv, StopWatch.stopAndGetElapsed("ExecuteMethodInterceptor"));
|
||||
Trace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,10 @@ public class ConnectionCloseInterceptor implements StaticBeforeInterceptor {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("before " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
if (JDBCScope.isInternal()) {
|
||||
logger.info("internal jdbc scope. skip trace");
|
||||
return;
|
||||
}
|
||||
// close의 경우 호출이 실패하더라도 데이터를 삭제해야함.
|
||||
if (target instanceof Connection) {
|
||||
this.setUrl.invoke(target, new Object[]{null});
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.profiler.util.InterceptorUtils;
|
||||
import com.profiler.util.MetaObject;
|
||||
import com.profiler.util.StringUtils;
|
||||
|
||||
@Deprecated
|
||||
public class ConnectionCreateInterceptor implements StaticAfterInterceptor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(ConnectionCreateInterceptor.class.getName());
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DriverInterceptor implements StaticAroundInterceptor {
|
||||
public class DriverConnectInterceptor implements StaticAroundInterceptor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(ConnectionCreateInterceptor.class.getName());
|
||||
private final MetaObject setUrl = new MetaObject("__setUrl", String.class);
|
||||
@@ -14,15 +14,15 @@ public class JDBCScope {
|
||||
};
|
||||
|
||||
public static void pushScope() {
|
||||
scope.set(true);
|
||||
scope.set(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public static boolean isInternal() {
|
||||
return scope.get();
|
||||
return scope.get() != null;
|
||||
}
|
||||
|
||||
public static void popScope() {
|
||||
scope.set(false);
|
||||
scope.set(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -23,6 +23,10 @@ public class PreparedStatementBindVariableInterceptor implements StaticAfterInte
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("after " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result);
|
||||
}
|
||||
if (JDBCScope.isInternal()) {
|
||||
logger.info("internal jdbc scope. skip trace");
|
||||
return;
|
||||
}
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
+4
@@ -25,6 +25,10 @@ public class PreparedStatementCreateInterceptor implements StaticAfterIntercepto
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("after " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result);
|
||||
}
|
||||
if (JDBCScope.isInternal()) {
|
||||
logger.info("internal jdbc scope. skip trace");
|
||||
return;
|
||||
}
|
||||
if (!InterceptorUtils.isSuccess(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+1
@@ -30,6 +30,7 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
|
||||
logger.info("before " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
if (JDBCScope.isInternal()) {
|
||||
logger.info("internal jdbc scope. skip trace");
|
||||
return;
|
||||
}
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
|
||||
@@ -25,6 +25,10 @@ public class StatementCreateInterceptor implements StaticAfterInterceptor {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("after " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result);
|
||||
}
|
||||
if (JDBCScope.isInternal()) {
|
||||
logger.info("internal jdbc scope. skip trace");
|
||||
return;
|
||||
}
|
||||
if (!InterceptorUtils.isSuccess(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-2
@@ -26,9 +26,8 @@ public class StatementExecuteQueryInterceptor implements StaticAroundInterceptor
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("before " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
new Exception("executeQuery").printStackTrace();
|
||||
;
|
||||
if (JDBCScope.isInternal()) {
|
||||
logger.info("internal jdbc scope. skip trace");
|
||||
return;
|
||||
}
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
|
||||
+1
@@ -28,6 +28,7 @@ public class StatementExecuteUpdateInterceptor implements StaticAroundIntercepto
|
||||
logger.info("before " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
if (JDBCScope.isInternal()) {
|
||||
logger.info("internal jdbc scope. skip trace");
|
||||
return;
|
||||
}
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
|
||||
@@ -24,6 +24,7 @@ public class TransactionInterceptor implements StaticAroundInterceptor {
|
||||
logger.info("before " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
if (JDBCScope.isInternal()) {
|
||||
logger.info("internal jdbc scope. skip trace");
|
||||
return;
|
||||
}
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.profiler.modifier.db.mysql;
|
||||
|
||||
import com.mysql.jdbc.NonRegisteringDriver;
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
import com.profiler.interceptor.bci.ByteCodeInstrumentor;
|
||||
import com.profiler.interceptor.bci.InstrumentClass;
|
||||
@@ -36,7 +35,7 @@ public class MySQLNonRegisteringDriverModifier extends AbstractModifier {
|
||||
InstrumentClass mysqlConnection = byteCodeInstrumentor.getClass(javassistClassName);
|
||||
|
||||
|
||||
Interceptor createConnection = new DriverInterceptor();
|
||||
Interceptor createConnection = new DriverConnectInterceptor();
|
||||
String[] params = new String[]{
|
||||
"java.lang.String", "java.util.Properties"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user