Skip to content
Merged

Dev #113

10 changes: 4 additions & 6 deletions scouter.agent.java/src/scouter/AnyTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
package scouter;

import scouter.agent.netio.data.DataProxy;
import scouter.agent.trace.AlertProxy;
import scouter.agent.trace.TraceApiCall;
import scouter.agent.trace.TraceContext;
import scouter.agent.trace.TraceContextManager;
import scouter.agent.trace.TraceMain;
import scouter.lang.pack.XLogTypes;
import scouter.util.HashUtil;
import scouter.util.KeyGen;

public class AnyTrace {
Expand All @@ -42,7 +40,7 @@ public static void setServiceName(String name) {
}

public static void serviceError(String emsg) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null && ctx.error != 0) { // already started
ctx.error = DataProxy.sendError(emsg);
}
Expand Down Expand Up @@ -70,7 +68,7 @@ public static Object startApicall(String name, long apiTxid) {

public static void setApicallName(String name) {
try {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null) {
if (ctx.apicall_name != null) { // already started subcall only
ctx.apicall_name = name;
Expand All @@ -86,7 +84,7 @@ public static void endApicall(Object stat, Throwable thr) {

public static void desc(String desc) {
try {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null) {
ctx.desc = desc;
}
Expand All @@ -96,7 +94,7 @@ public static void desc(String desc) {

public static void login(String login) {
try {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null) {
ctx.login = login;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class JDBCPreparedStatementASM implements IASM, Opcodes {
public final HashSet<String> target = HookingSet.getHookingClassSet(Configure.getInstance().hook_jdbc_pstmt_classes);
public final HashSet<String> noField = new HashSet<String>();
public JDBCPreparedStatementASM() {
target.add("org.mariadb.jdbc.MariaDbClientPreparedStatement");
target.add("org/mariadb/jdbc/MySQLPreparedStatement");
target.add("oracle/jdbc/driver/OraclePreparedStatement");
target.add("org/postgresql/jdbc2/AbstractJdbc2Statement");
Expand All @@ -53,6 +54,7 @@ public JDBCPreparedStatementASM() {
target.add("cubrid/jdbc/driver/CUBRIDPreparedStatement");

// @skyworker - MySQL ServerPreparedStatement는 특별히 필드를 추가하지 않음
noField.add("org.mariadb.jdbc.MariaDbClientPreparedStatement");
noField.add("com/mysql/jdbc/ServerPreparedStatement");
noField.add("jdbc/FakePreparedStatement2");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class JDBCStatementASM implements IASM, Opcodes {
public final HashSet<String> target = HookingSet.getHookingClassSet(Configure.getInstance().hook_jdbc_stmt_classes);
public JDBCStatementASM() {

target.add("org.mariadb.jdbc.MariaDbStatement");
target.add("org/mariadb/jdbc/MySQLStatement");
target.add("oracle/jdbc/driver/OracleStatement");
target.add("com/mysql/jdbc/StatementImpl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static HashSet<String> getHookingClassSet(String arg) {
if(c ==null)
return classSet;
for (int i = 0; i < c.length; i++) {
classSet.add(c[i]);
classSet.add(c[i].replace('.', '/').trim());
}
return classSet;
}
Expand Down
2 changes: 1 addition & 1 deletion scouter.agent.java/src/scouter/agent/plugin/WrContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void profile(String msg) {

/**
* add xlog profile
* profile diplay like --> msg #value elapsed
* profile display like --> msg #value elapsed
* @param msg message
* @param value any value to display on a profile.
* @param elapsed any value to display on a profile.
Expand Down
10 changes: 5 additions & 5 deletions scouter.agent.java/src/scouter/agent/trace/TraceApiCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public Stat(TraceContext ctx) {
}
}
public static void apiInfo(String className, String methodName, String methodDesc, Object _this, Object[] arg) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null && arg.length >= 2) {
ctx.apicall_target = arg[0] + ":" + arg[1];
}
}
public static Object startApicall(String className, String methodName, String methodDesc, Object _this, Object[] arg) {
try {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null) {
return null;
}
Expand All @@ -85,7 +85,7 @@ public static Object startApicall(String className, String methodName, String me
return null;
}
public static Object startApicall(String name, long apiTxid) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null)
return null;
if (ctx.apicall_name != null) {
Expand Down Expand Up @@ -153,7 +153,7 @@ public static void endApicall(Object stat, Object returnValue, Throwable thr) {
public static Object startSocket(Socket socket, SocketAddress addr, int timeout) {
if (!(addr instanceof InetSocketAddress))
return null;
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null) {
if (Configure.getInstance().trace_background_socket_enabled) {
InetSocketAddress inet = (InetSocketAddress) addr;
Expand Down Expand Up @@ -211,7 +211,7 @@ public static void endSocket(Object stat, Throwable thr) {
}
}
public static void open(File file) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null) {
MessageStep m = new MessageStep();
m.start_time = (int) (System.currentTimeMillis() - ctx.startTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package scouter.agent.trace;

import java.util.Enumeration;

import scouter.agent.Configure;
import scouter.util.LongEnumer;
import scouter.util.LongKeyMap;

import java.util.Enumeration;

public class TraceContextManager {

private static LongKeyMap<TraceContext> entry = new LongKeyMap<TraceContext>();
Expand Down Expand Up @@ -66,7 +66,7 @@ public static TraceContext getContext(long key) {
return entry.get(key);
}

public static TraceContext getLocalContext() {
public static TraceContext getContext() {
return local.get();
}

Expand Down
24 changes: 12 additions & 12 deletions scouter.agent.java/src/scouter/agent/trace/TraceMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Stat(TraceContext ctx) {

public static Object startHttpService(Object req, Object res) {
try {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null) {
return null;
}
Expand All @@ -77,7 +77,7 @@ public static Object startHttpService(Object req, Object res) {

public static Object startHttpFilter(Object req, Object res) {
try {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null) {
return null;
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public static void endHttpService(Object stat, Throwable thr) {
if (thr == null)
return;
try {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null && ctx.error == 0) {
Configure conf = Configure.getInstance();
String emsg = thr.toString();
Expand Down Expand Up @@ -350,7 +350,7 @@ public static boolean isStaticContents(String serviceName) {
public static Object startService(String name, String className, String methodName, String methodDesc, Object _this,
Object[] arg, byte xType) {
try {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx != null) {
return null;
}
Expand Down Expand Up @@ -484,7 +484,7 @@ private static int errorCheck(TraceContext ctx, Throwable thr) {
}

public static void capArgs(String className, String methodName, String methodDesc, Object this1, Object[] arg) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null)
return;
// MessageStep step = new MessageStep();
Expand All @@ -499,7 +499,7 @@ public static void capArgs(String className, String methodName, String methodDes
}

public static void jspServlet(Object[] arg) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null || arg.length < 3)
return;
HashedMessageStep step = new HashedMessageStep();
Expand Down Expand Up @@ -556,7 +556,7 @@ private static String toStringTHIS(String type, String className, String methodD
}

public static void capThis(String className, String methodDesc, Object this0) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null)
return;
// MessageStep step = new MessageStep();
Expand All @@ -571,7 +571,7 @@ public static void capThis(String className, String methodDesc, Object this0) {
}

public static void capReturn(String className, String methodName, String methodDesc, Object this1, Object rtn) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null)
return;
PluginCaptureTrace.capReturn(ctx, new HookReturn(className, methodName, methodDesc, this1, rtn));
Expand All @@ -580,7 +580,7 @@ public static void capReturn(String className, String methodName, String methodD
public static Object startMethod(int hash, String classMethod) {
if (conf.profile_method_enabled == false)
return null;
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null) {
if (conf._trace_auto_service_enabled) {
Object localContext = startService(classMethod, null, null, null, null, null, XLogTypes.APP_SERVICE);
Expand Down Expand Up @@ -630,15 +630,15 @@ public static void endMethod(Object localContext, Throwable thr) {
}

public static void setServiceName(String name) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null || name == null)
return;
ctx.serviceName = name;
ctx.serviceHash = HashUtil.hash(name);
}

public static void setStatus(int httpStatus) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null)
return;
ctx.status = httpStatus;
Expand Down Expand Up @@ -669,7 +669,7 @@ public static XLogPack txperf(long endtime, long txid, int service_hash, String
}

public static void addMessage(String msg) {
TraceContext ctx = TraceContextManager.getLocalContext();
TraceContext ctx = TraceContextManager.getContext();
if (ctx == null)
return;
MessageStep p = new MessageStep();
Expand Down
Loading