diff --git a/src/main/java/com/profiler/modifier/db/mysql/interceptors/CloseConnectionInterceptor.java b/src/main/java/com/profiler/modifier/db/mysql/interceptors/CloseConnectionInterceptor.java index f45a381c4..ff1b9bf93 100644 --- a/src/main/java/com/profiler/modifier/db/mysql/interceptors/CloseConnectionInterceptor.java +++ b/src/main/java/com/profiler/modifier/db/mysql/interceptors/CloseConnectionInterceptor.java @@ -8,23 +8,18 @@ import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; - public class CloseConnectionInterceptor implements StaticBeforeInterceptor { - private final Logger logger = Logger.getLogger(CloseConnectionInterceptor.class.getName()); - - public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) { - if (logger.isLoggable(Level.INFO)) { - logger.info("before " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args)); - } - - if (target instanceof Connection) { - ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace(); - connectionTrace.closeConnection((Connection) target); - } - } - - + private final Logger logger = Logger.getLogger(CloseConnectionInterceptor.class.getName()); + public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) { + if (logger.isLoggable(Level.INFO)) { + logger.info("before " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args)); + } + if (target instanceof Connection) { + ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace(); + connectionTrace.closeConnection((Connection) target); + } + } } diff --git a/src/main/java/com/profiler/modifier/db/mysql/interceptors/CreateConnectionInterceptor.java b/src/main/java/com/profiler/modifier/db/mysql/interceptors/CreateConnectionInterceptor.java index 6d65fae8e..735408018 100644 --- a/src/main/java/com/profiler/modifier/db/mysql/interceptors/CreateConnectionInterceptor.java +++ b/src/main/java/com/profiler/modifier/db/mysql/interceptors/CreateConnectionInterceptor.java @@ -1,35 +1,34 @@ package com.profiler.modifier.db.mysql.interceptors; -import com.profiler.interceptor.StaticAfterInterceptor; -import com.profiler.modifier.db.ConnectionTrace; -import com.profiler.util.InterceptorUtils; - import java.sql.Connection; import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; +import com.profiler.interceptor.StaticAfterInterceptor; +import com.profiler.modifier.db.ConnectionTrace; +import com.profiler.util.InterceptorUtils; + public class CreateConnectionInterceptor implements StaticAfterInterceptor { - private final Logger logger = Logger.getLogger(CreateConnectionInterceptor.class.getName()); + private final Logger logger = Logger.getLogger(CreateConnectionInterceptor.class.getName()); - @Override - public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) { - if (logger.isLoggable(Level.INFO)) { - logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result); - } + @Override + public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) { + if (logger.isLoggable(Level.INFO)) { + logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result); + } - if (InterceptorUtils.isThrowable(result)) { - return; - } + if (InterceptorUtils.isThrowable(result)) { + return; + } - if (result instanceof Connection) { - Object url = args[4]; - if (url instanceof String) { - ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace(); - connectionTrace.createConnection((Connection)result, (String) url); - } - } - - } + if (result instanceof Connection) { + Object url = args[4]; + if (url instanceof String) { + ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace(); + connectionTrace.createConnection((Connection) result, (String) url); + } + } + } } diff --git a/src/main/java/com/profiler/modifier/db/mysql/interceptors/CreateStatementInterceptor.java b/src/main/java/com/profiler/modifier/db/mysql/interceptors/CreateStatementInterceptor.java index 9d32b2fad..1f2734274 100644 --- a/src/main/java/com/profiler/modifier/db/mysql/interceptors/CreateStatementInterceptor.java +++ b/src/main/java/com/profiler/modifier/db/mysql/interceptors/CreateStatementInterceptor.java @@ -13,46 +13,43 @@ import java.util.logging.Logger; public class CreateStatementInterceptor implements StaticAfterInterceptor { - private final Logger logger = Logger.getLogger(CreateStatementInterceptor.class.getName()); + private final Logger logger = Logger.getLogger(CreateStatementInterceptor.class.getName()); - private Method setUrl = null; + private Method setUrl = null; - @Override - public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) { - if (logger.isLoggable(Level.INFO)) { - logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result); - } - if (Trace.getCurrentTraceId() == null) { - return; - } - if (target instanceof Connection) { - ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace(); - String connectionUrl = connectionTrace.getConnectionUrl((Connection) target); - setUrl(result, connectionUrl); - } - - - } - - private void setUrl(Object result, String connectionUrl) { - try { - if (setUrl == null) { - setUrl = result.getClass().getMethod("__setUrl", String.class); - } - setUrl.invoke(result, connectionUrl); - } catch (NoSuchMethodException e) { - if (logger.isLoggable(Level.WARNING)) { - logger.log(Level.WARNING, e.getMessage(), e); - } - } catch (InvocationTargetException e) { - if (logger.isLoggable(Level.WARNING)) { - logger.log(Level.WARNING, e.getMessage(), e); - } - } catch (IllegalAccessException e) { - if (logger.isLoggable(Level.WARNING)) { - logger.log(Level.WARNING, e.getMessage(), e); - } - } - } + @Override + public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) { + if (logger.isLoggable(Level.INFO)) { + logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result); + } + if (Trace.getCurrentTraceId() == null) { + return; + } + if (target instanceof Connection) { + ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace(); + String connectionUrl = connectionTrace.getConnectionUrl((Connection) target); + setUrl(result, connectionUrl); + } + } + private void setUrl(Object result, String connectionUrl) { + try { + if (setUrl == null) { + setUrl = result.getClass().getMethod("__setUrl", String.class); + } + setUrl.invoke(result, connectionUrl); + } catch (NoSuchMethodException e) { + if (logger.isLoggable(Level.WARNING)) { + logger.log(Level.WARNING, e.getMessage(), e); + } + } catch (InvocationTargetException e) { + if (logger.isLoggable(Level.WARNING)) { + logger.log(Level.WARNING, e.getMessage(), e); + } + } catch (IllegalAccessException e) { + if (logger.isLoggable(Level.WARNING)) { + logger.log(Level.WARNING, e.getMessage(), e); + } + } + } } diff --git a/src/main/java/com/profiler/modifier/db/mysql/interceptors/ExecuteQueryMethodInterceptor.java b/src/main/java/com/profiler/modifier/db/mysql/interceptors/ExecuteQueryMethodInterceptor.java index 2ebf77485..e225ece27 100644 --- a/src/main/java/com/profiler/modifier/db/mysql/interceptors/ExecuteQueryMethodInterceptor.java +++ b/src/main/java/com/profiler/modifier/db/mysql/interceptors/ExecuteQueryMethodInterceptor.java @@ -18,25 +18,28 @@ import java.util.logging.Logger; */ public class ExecuteQueryMethodInterceptor implements StaticAroundInterceptor { - private final Logger logger = Logger.getLogger(ExecuteQueryMethodInterceptor.class.getName()); + private final Logger logger = Logger.getLogger(ExecuteQueryMethodInterceptor.class.getName()); - private Method getUrl = null; + private Method getUrl = null; @Override public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) { - if (logger.isLoggable(Level.INFO)) { - logger.info("before " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args)); - } - if (Trace.getCurrentTraceId() == null) { - return; - } + if (logger.isLoggable(Level.INFO)) { + logger.info("before " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args)); + } + + if (Trace.getCurrentTraceId() == null) { + return; + } + + Trace.traceBlockBegin(); try { /** * If method was not called by request handler, we skip tagging. */ - String url = getUrl(target); - Trace.recordRpcName("mysql", url); + String url = getUrl(target); + Trace.recordRpcName("mysql", url); if (args.length > 0) { Trace.recordAttibute("Query", args[0]); @@ -47,43 +50,46 @@ public class ExecuteQueryMethodInterceptor implements StaticAroundInterceptor { StopWatch.start("ExecuteQueryMethodInterceptor"); } catch (Exception e) { e.printStackTrace(); + } finally { + Trace.traceBlockEnd(); } } - private String getUrl(Object target) { - try { - // TODO classloading 시 해당 mehtod를 한번에 가져올수 없는지 검토. - if(getUrl == null) { - getUrl = target.getClass().getMethod("__getUrl"); - } - return (String) getUrl.invoke(target); - } catch (NoSuchMethodException e) { - if (logger.isLoggable(Level.WARNING)) { + private String getUrl(Object target) { + try { + // TODO classloading 시 해당 mehtod를 한번에 가져올수 없는지 검토. + if (getUrl == null) { + getUrl = target.getClass().getMethod("__getUrl"); + } + return (String) getUrl.invoke(target); + } catch (NoSuchMethodException e) { + if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, e.getMessage(), e); } - } catch (IllegalAccessException e) { - if (logger.isLoggable(Level.WARNING)) { + } catch (IllegalAccessException e) { + if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, e.getMessage(), e); } - } catch (InvocationTargetException e) { - if (logger.isLoggable(Level.WARNING)) { + } catch (InvocationTargetException e) { + if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, e.getMessage(), e); } - } - return null; - } + } + return null; + } - @Override + @Override public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) { if (logger.isLoggable(Level.INFO)) { - logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result); - } - - if (Trace.getCurrentTraceId() == null) { - return; + logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result); } - + if (Trace.getCurrentTraceId() == null) { + return; + } + + Trace.traceBlockBegin(); Trace.record(Annotation.ClientRecv, StopWatch.stopAndGetElapsed("ExecuteQueryMethodInterceptor")); + Trace.traceBlockEnd(); } } diff --git a/src/main/java/com/profiler/modifier/db/mysql/interceptors/ExecuteUpdateMethodInterceptor.java b/src/main/java/com/profiler/modifier/db/mysql/interceptors/ExecuteUpdateMethodInterceptor.java index d112652cf..95b905f75 100644 --- a/src/main/java/com/profiler/modifier/db/mysql/interceptors/ExecuteUpdateMethodInterceptor.java +++ b/src/main/java/com/profiler/modifier/db/mysql/interceptors/ExecuteUpdateMethodInterceptor.java @@ -17,13 +17,16 @@ public class ExecuteUpdateMethodInterceptor implements StaticAroundInterceptor { @Override public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) { System.out.println("ExecuteUpdateMethodInterceptor.before"); + + /** + * If method was not called by request handler, we skip tagging. + */ + if (Trace.getCurrentTraceId() == null) { + return; + } + try { - /** - * If method was not called by request handler, we skip tagging. - */ - if (Trace.getCurrentTraceId() == null) { - return; - } + Trace.traceBlockBegin(); Trace.recordRpcName("mysql", ""); @@ -40,6 +43,8 @@ public class ExecuteUpdateMethodInterceptor implements StaticAroundInterceptor { StopWatch.start("ExecuteUpdateMethodInterceptor"); } catch (Exception e) { e.printStackTrace(); + } finally { + Trace.traceBlockEnd(); } } @@ -49,7 +54,9 @@ public class ExecuteUpdateMethodInterceptor implements StaticAroundInterceptor { if (Trace.getCurrentTraceId() == null) { return; } - + + Trace.traceBlockBegin(); Trace.record(Annotation.ClientRecv, StopWatch.stopAndGetElapsed("ExecuteUpdateMethodInterceptor")); + Trace.traceBlockEnd(); } }