Merge commit 'ee7cf9da2bd3e6beaf6c53c75092a8fac4de391a' into feature/3.0
This commit is contained in:
commit
dfee12c565
1
pom.xml
1
pom.xml
|
|
@ -155,6 +155,7 @@
|
|||
<instrumentation>
|
||||
<excludes>
|
||||
<exclude>com/a/eye/skywalking/trace/proto/*.class</exclude>
|
||||
<exclude>com/a/eye/skywalking/sniffer/mock/**/*.class</exclude>
|
||||
</excludes>
|
||||
</instrumentation>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
<modules>
|
||||
<module>skywalking-trace</module>
|
||||
<module>skywalking-logging</module>
|
||||
<module>skywalking-util</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>skywalking-commons</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>3.0-2017</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>skywalking-logging</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>skywalking-logging</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<modules>
|
||||
<module>skywalking-logging-api</module>
|
||||
<module>skywalking-logging-impl-log4j2</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>skywalking-logging</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>3.0-2017</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>skywalking-logging-api</artifactId>
|
||||
|
||||
</project>
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>skywalking-logging</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>3.0-2017</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>skywalking-logging-impl-log4j2</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-logging-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
package com.a.eye.skywalking.api.logging.impl.log4j2;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/11.
|
||||
*/
|
||||
public class Log4j2Logger implements ILog {
|
||||
private Logger logger;
|
||||
|
||||
public Log4j2Logger(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message, Object... arguments) {
|
||||
logger.info(message, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object... arguments) {
|
||||
logger.warn(format, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arguments, Throwable e) {
|
||||
logger.warn(format, arguments, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message, Throwable e) {
|
||||
logger.error(message, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message, Object argument, Throwable e) {
|
||||
logger.error(message, argument, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnable() {
|
||||
return logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnable() {
|
||||
return logger.isInfoEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnable() {
|
||||
return logger.isWarnEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnable() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format) {
|
||||
logger.debug(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object... arguments) {
|
||||
logger.debug(format, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format) {
|
||||
logger.error(format);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.a.eye.skywalking.api.logging.impl.log4j2;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogResolver;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/11.
|
||||
*/
|
||||
public class Log4j2Resolver implements LogResolver {
|
||||
@Override
|
||||
public ILog getLogger(Class<?> clazz) {
|
||||
return new Log4j2Logger(LogManager.getLogger(clazz));
|
||||
}
|
||||
}
|
||||
|
|
@ -12,11 +12,6 @@
|
|||
<artifactId>skywalking-trace</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-logging-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-util</artifactId>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import com.a.eye.skywalking.agent.junction.SkyWalkingEnhanceMatcher;
|
|||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import com.a.eye.skywalking.api.conf.SnifferConfigInitializer;
|
||||
import com.a.eye.skywalking.api.logging.EasyLogResolver;
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.AbstractClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.api.plugin.PluginBootstrap;
|
||||
import com.a.eye.skywalking.api.plugin.PluginFinder;
|
||||
|
|
@ -26,8 +26,8 @@ import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
/**
|
||||
* The main entrance of sky-waking agent.
|
||||
* It bases on javaagent mechanism.
|
||||
* The main entrance of sky-waking agent,
|
||||
* based on javaagent mechanism.
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
|
|
@ -36,11 +35,6 @@
|
|||
<artifactId>disruptor</artifactId>
|
||||
<version>3.3.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-logging-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ public class Constants {
|
|||
* This is the version, which will be the first segment of traceid.
|
||||
* Ref {@link TraceIdGenerator#generate()}
|
||||
*/
|
||||
public static String SDK_VERSION = "302017";
|
||||
public final static String SDK_VERSION = "302017";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.conf;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import com.a.eye.skywalking.api.util.ConfigInitializer;
|
||||
import com.a.eye.skywalking.api.util.StringUtil;
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ import java.io.InputStream;
|
|||
import java.util.Properties;
|
||||
|
||||
public class SnifferConfigInitializer {
|
||||
private static ILog logger = LogManager.getLogger(SnifferConfigInitializer.class);
|
||||
private static ILog logger = LogManager.getLogger(SnifferConfigInitializer.class);
|
||||
|
||||
public static void initialize() {
|
||||
InputStream configFileStream;
|
||||
|
|
@ -32,24 +32,34 @@ public class SnifferConfigInitializer {
|
|||
logger.error("Failed to read the config file, sky-walking api run in default config.", e);
|
||||
}
|
||||
}
|
||||
Config.SkyWalking.USERNAME = System.getProperty("username");
|
||||
Config.SkyWalking.APPLICATION_CODE = System.getProperty("applicationCode");
|
||||
Config.SkyWalking.SERVERS = System.getProperty("servers");
|
||||
|
||||
if(StringUtil.isEmpty(Config.SkyWalking.USERNAME)){
|
||||
String username = System.getProperty("username");
|
||||
if (!StringUtil.isEmpty(username)) {
|
||||
Config.SkyWalking.USERNAME = username;
|
||||
}
|
||||
String applicationCode = System.getProperty("applicationCode");
|
||||
if (!StringUtil.isEmpty(applicationCode)) {
|
||||
Config.SkyWalking.APPLICATION_CODE = applicationCode;
|
||||
}
|
||||
String servers = System.getProperty("servers");
|
||||
if(!StringUtil.isEmpty(servers)) {
|
||||
Config.SkyWalking.SERVERS = servers;
|
||||
}
|
||||
|
||||
if (StringUtil.isEmpty(Config.SkyWalking.USERNAME)) {
|
||||
throw new ExceptionInInitializerError("'-Dusername=' is missing.");
|
||||
}
|
||||
if(StringUtil.isEmpty(Config.SkyWalking.APPLICATION_CODE)){
|
||||
if (StringUtil.isEmpty(Config.SkyWalking.APPLICATION_CODE)) {
|
||||
throw new ExceptionInInitializerError("'-DapplicationCode=' is missing.");
|
||||
}
|
||||
if(StringUtil.isEmpty(Config.SkyWalking.SERVERS)){
|
||||
if (StringUtil.isEmpty(Config.SkyWalking.SERVERS)) {
|
||||
throw new ExceptionInInitializerError("'-Dservers=' is missing.");
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream fetchAuthFileInputStream() {
|
||||
try {
|
||||
return new FileInputStream(Config.SkyWalking.AGENT_BASE_PATH + File.separator + "/sky-walking.config");
|
||||
return new FileInputStream(Config.SkyWalking.AGENT_BASE_PATH + File.separator + "sky-walking.config");
|
||||
} catch (Exception e) {
|
||||
logger.warn("sky-walking.config is missing, use default config.");
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogResolver;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/26.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
|
||||
import com.a.eye.skywalking.api.util.LoggingUtil;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
|
@ -34,7 +31,7 @@ public class EasyLogger implements ILog {
|
|||
}
|
||||
|
||||
if (e != null) {
|
||||
WriterFactory.getLogWriter().writeError(LoggingUtil.fetchThrowableStack(e));
|
||||
WriterFactory.getLogWriter().writeError(ThrowableFormatter.format(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,18 +73,13 @@ public class EasyLogger implements ILog {
|
|||
logger(WARN, replaceParam(format, arguments), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arguments, Throwable e) {
|
||||
logger(WARN, replaceParam(format, arguments), e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Throwable e) {
|
||||
logger(ERROR, format, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object arguments, Throwable e) {
|
||||
public void error(Throwable e, String format, Object... arguments) {
|
||||
logger(ERROR, replaceParam(format, arguments), e);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.api.logging.api;
|
||||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
/**
|
||||
* The Log interface.
|
||||
|
|
@ -14,11 +14,9 @@ public interface ILog {
|
|||
|
||||
void warn(String format, Object... arguments);
|
||||
|
||||
void warn(String format, Object arguments, Throwable e);
|
||||
|
||||
void error(String format, Throwable e);
|
||||
|
||||
void error(String format, Object arguments, Throwable e);
|
||||
void error(Throwable e, String format, Object... arguments);
|
||||
|
||||
boolean isDebugEnable();
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.api.logging.api;
|
||||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
/**
|
||||
* LogManager is the {@link LogResolver} implementation manager.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.api.logging.api;
|
||||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
/**
|
||||
* {@link LogResolver} just do only one thing: return the {@link ILog} implementation.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.api.logging.api;
|
||||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -8,7 +8,9 @@ package com.a.eye.skywalking.api.logging.api;
|
|||
* Created by xin on 2016/11/10.
|
||||
*/
|
||||
public enum NoopLogger implements ILog {
|
||||
INSTANCE;
|
||||
INSTANCE {
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
|
|
@ -25,20 +27,11 @@ public enum NoopLogger implements ILog {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arguments, Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object argument, Throwable e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnable() {
|
||||
return false;
|
||||
|
|
@ -73,4 +66,9 @@ public enum NoopLogger implements ILog {
|
|||
public void error(String format) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Throwable e, String format, Object... arguments) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package com.a.eye.skywalking.api.logging;
|
|||
|
||||
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import com.a.eye.skywalking.api.util.LoggingUtil;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
|
|
@ -97,15 +96,15 @@ public class SyncFileWriter implements IWriter {
|
|||
try {
|
||||
File file = new File(Config.Logging.LOG_DIR_NAME, Config.Logging.SYSTEM_ERROR_LOG_FILE_NAME);
|
||||
fileOutputStream = new FileOutputStream(file, true);
|
||||
fileOutputStream.write(("Failed to init sync File Writer.\n" + LoggingUtil.fetchThrowableStack(e)).getBytes());
|
||||
fileOutputStream.write(("Failed to init sync File Writer.\n" + ThrowableFormatter.format(e)).getBytes());
|
||||
} catch (Exception e1) {
|
||||
System.err.print(LoggingUtil.fetchThrowableStack(e1));
|
||||
System.err.print(ThrowableFormatter.format(e1));
|
||||
} finally {
|
||||
if (fileOutputStream != null) {
|
||||
try {
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e1) {
|
||||
System.err.print(LoggingUtil.fetchThrowableStack(e1));
|
||||
System.err.print(ThrowableFormatter.format(e1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.api.util;
|
||||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
|
@ -6,8 +6,8 @@ import java.io.IOException;
|
|||
/**
|
||||
* Created by xin on 16-6-24.
|
||||
*/
|
||||
public class LoggingUtil {
|
||||
public static String fetchThrowableStack(Throwable e) {
|
||||
public class ThrowableFormatter {
|
||||
public static String format(Throwable e) {
|
||||
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
||||
e.printStackTrace(new java.io.PrintWriter(buf, true));
|
||||
String expMessage = buf.toString();
|
||||
|
|
@ -3,9 +3,6 @@ package com.a.eye.skywalking.api.logging;
|
|||
import com.a.eye.skywalking.api.conf.Config;
|
||||
|
||||
public class WriterFactory {
|
||||
private WriterFactory(){
|
||||
}
|
||||
|
||||
public static IWriter getLogWriter(){
|
||||
if (Config.SkyWalking.IS_PREMAIN_MODE){
|
||||
return SyncFileWriter.instance();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.api.util.StringUtil;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
|
||||
import java.net.URL;
|
||||
|
|
@ -37,7 +37,7 @@ public class PluginBootstrap {
|
|||
try {
|
||||
PluginCfg.INSTANCE.load(pluginUrl.openStream());
|
||||
} catch (Throwable t) {
|
||||
logger.error("plugin [{}] init failure.", new Object[] {pluginUrl}, t);
|
||||
logger.error(t, "plugin [{}] init failure.", pluginUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ public class PluginBootstrap {
|
|||
plugin.setClassTypePool(classTypePool);
|
||||
plugins.add(plugin);
|
||||
} catch (Throwable t) {
|
||||
logger.error("loade plugin [{}] failure.", new Object[] {pluginClassName}, t);
|
||||
logger.error(t, "loade plugin [{}] failure.", pluginClassName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.ClassFileLocator;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin.bytebuddy;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.method.ParameterList;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
/**
|
||||
|
|
@ -39,8 +40,9 @@ public class ArgumentTypeNameMatch implements ElementMatcher<MethodDescription>
|
|||
*/
|
||||
@Override
|
||||
public boolean matches(MethodDescription target) {
|
||||
if (target.getParameters().size() > index) {
|
||||
return target.getParameters().get(index).getType().asErasure().getName().equals(argumentTypeName);
|
||||
ParameterList<?> parameters = target.getParameters();
|
||||
if (parameters.size() > index) {
|
||||
return parameters.get(index).getType().asErasure().getName().equals(argumentTypeName);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.loader.InterceptorInstanceLoader;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.AbstractClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.api.plugin.PluginException;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.loader.InterceptorInstanceLoader;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import net.bytebuddy.implementation.bind.annotation.*;
|
||||
|
|
@ -55,7 +55,7 @@ public class ClassInstanceMethodsInterceptor {
|
|||
try {
|
||||
interceptor.beforeMethod(instanceContext, interceptorContext, result);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] before method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
logger.error(t,"class[{}] before method[{}] intercept failure", obj.getClass(), method.getName());
|
||||
}
|
||||
|
||||
Object ret = null;
|
||||
|
|
@ -69,14 +69,14 @@ public class ClassInstanceMethodsInterceptor {
|
|||
try {
|
||||
interceptor.handleMethodException(t, instanceContext, interceptorContext);
|
||||
} catch (Throwable t2) {
|
||||
logger.error("class[{}] handle method[{}] exception failue:{}", new Object[] {obj.getClass(), method.getName(), t2.getMessage()}, t2);
|
||||
logger.error(t2, "class[{}] handle method[{}] exception failure", obj.getClass(), method.getName());
|
||||
}
|
||||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(instanceContext, interceptorContext, ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] after method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
logger.error(t, "class[{}] after method[{}] intercept failure", obj.getClass(), method.getName());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.loader.InterceptorInstanceLoader;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.Origin;
|
||||
|
|
@ -55,7 +55,7 @@ public class ClassStaticMethodsInterceptor {
|
|||
try {
|
||||
interceptor.beforeMethod(interceptorContext, result);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] before static method[{}] intercept failue:{}", new Object[] {clazz, method.getName(), t.getMessage()}, t);
|
||||
logger.error(t, "class[{}] before static method[{}] intercept failure", clazz, method.getName());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -70,14 +70,14 @@ public class ClassStaticMethodsInterceptor {
|
|||
try {
|
||||
interceptor.handleMethodException(t, interceptorContext);
|
||||
} catch (Throwable t2) {
|
||||
logger.error("class[{}] handle static method[{}] exception failue:{}", new Object[] {clazz, method.getName(), t2.getMessage()}, t2);
|
||||
logger.error(t2, "class[{}] handle static method[{}] exception failure", clazz, method.getName(), t2.getMessage());
|
||||
}
|
||||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(interceptorContext, ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] after static method[{}] intercept failue:{}", new Object[] {clazz, method.getName(), t.getMessage()}, t);
|
||||
logger.error(t,"class[{}] after static method[{}] intercept failure:{}", clazz, method.getName(), t.getMessage());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.FieldProxy;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.loader;
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.a.eye.skywalking.api.conf;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class ConstantsTest {
|
||||
@Test
|
||||
public void testSDKVersion(){
|
||||
Assert.assertEquals("302017", Constants.SDK_VERSION);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.a.eye.skywalking.api.conf;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author wusheng
|
||||
*/
|
||||
public class SnifferConfigInitializerTest {
|
||||
|
||||
@Test
|
||||
public void testInitialize(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
SnifferConfigInitializer.initialize();
|
||||
|
||||
Assert.assertEquals("testUser", Config.SkyWalking.USERNAME);
|
||||
Assert.assertEquals("crmApp", Config.SkyWalking.APPLICATION_CODE);
|
||||
Assert.assertEquals("127.0.0.1:8080", Config.SkyWalking.SERVERS);
|
||||
|
||||
Assert.assertNotNull(Config.Disruptor.BUFFER_SIZE);
|
||||
Assert.assertNotNull(Config.Logging.LOG_DIR_NAME);
|
||||
Assert.assertNotNull(Config.Logging.LOG_FILE_NAME);
|
||||
Assert.assertNotNull(Config.Logging.MAX_LOG_FILE_LENGTH);
|
||||
Assert.assertNotNull(Config.Logging.SYSTEM_ERROR_LOG_FILE_NAME);
|
||||
}
|
||||
|
||||
@Test(expected = ExceptionInInitializerError.class)
|
||||
public void testErrorInitialize(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = true;
|
||||
SnifferConfigInitializer.initialize();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void reset(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class EasyLogResolverTest {
|
||||
@Test
|
||||
public void testGetLogger(){
|
||||
Assert.assertTrue(new EasyLogResolver().getLogger(EasyLogResolverTest.class) instanceof EasyLogger);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import java.io.PrintStream;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class EasyLoggerTest {
|
||||
private static PrintStream outRef;
|
||||
private static PrintStream errRef;
|
||||
|
||||
@BeforeClass
|
||||
public static void initAndHoldOut(){
|
||||
outRef = System.out;
|
||||
errRef = System.err;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLog(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
|
||||
PrintStream output = Mockito.mock(PrintStream.class);
|
||||
System.setOut(output);
|
||||
PrintStream err = Mockito.mock(PrintStream.class);
|
||||
System.setErr(err);
|
||||
EasyLogger logger = new EasyLogger(EasyLoggerTest.class);
|
||||
|
||||
Assert.assertTrue(logger.isDebugEnable());
|
||||
Assert.assertTrue(logger.isInfoEnable());
|
||||
Assert.assertTrue(logger.isWarnEnable());
|
||||
Assert.assertTrue(logger.isErrorEnable());
|
||||
|
||||
logger.debug("hello world");
|
||||
logger.debug("hello {}", "world");
|
||||
logger.info("hello world");
|
||||
logger.info("hello {}", "world");
|
||||
|
||||
logger.warn("hello {}", "world");
|
||||
logger.warn("hello world");
|
||||
logger.error("hello world");
|
||||
logger.error("hello world", new NullPointerException());
|
||||
logger.error(new NullPointerException(),"hello {}", "world");
|
||||
|
||||
Mockito.verify(output,times(4))
|
||||
.println(anyString());
|
||||
Mockito.verify(err,times(7))
|
||||
.println(anyString());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void reset(){
|
||||
System.setOut(outRef);
|
||||
System.setErr(errRef);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.api.logging.api;
|
||||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
|
|
@ -50,15 +50,11 @@ public class LogManagerTest {
|
|||
|
||||
}
|
||||
|
||||
@Override public void warn(String format, Object arguments, Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void error(String format, Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void error(String format, Object arguments, Throwable e) {
|
||||
@Override public void error(Throwable e, String format, Object... arguments) {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -91,3 +87,4 @@ public class LogManagerTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.a.eye.skywalking.api.logging.api;
|
||||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.a.eye.skywalking.api.logging.api.NoopLogger.INSTANCE;
|
||||
import static com.a.eye.skywalking.api.logging.NoopLogger.INSTANCE;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/27.
|
||||
|
|
@ -24,6 +24,5 @@ public class NoopLoggerTest {
|
|||
INSTANCE.warn("Any string", new Object[0], new NullPointerException());
|
||||
INSTANCE.error("Any string");
|
||||
INSTANCE.error("Any string", new NullPointerException());
|
||||
INSTANCE.error("Any string", new Object[0], new NullPointerException());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class STDOutWriterTest {
|
||||
private static PrintStream outRef;
|
||||
private static PrintStream errRef;
|
||||
|
||||
@BeforeClass
|
||||
public static void initAndHoldOut(){
|
||||
outRef = System.out;
|
||||
errRef = System.err;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrite(){
|
||||
PrintStream mockStream = Mockito.mock(PrintStream.class);
|
||||
System.setOut(mockStream);
|
||||
|
||||
STDOutWriter writer = new STDOutWriter();
|
||||
writer.write("hello");
|
||||
|
||||
Mockito.verify(mockStream,times(1)).println(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteError(){
|
||||
PrintStream mockStream = Mockito.mock(PrintStream.class);
|
||||
System.setErr(mockStream);
|
||||
|
||||
STDOutWriter writer = new STDOutWriter();
|
||||
writer.writeError("hello");
|
||||
|
||||
Mockito.verify(mockStream,times(1)).println(anyString());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void reset(){
|
||||
System.setOut(outRef);
|
||||
System.setErr(errRef);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class ThrowableFormatterTest {
|
||||
@Test
|
||||
public void testFormat(){
|
||||
NullPointerException exception = new NullPointerException();
|
||||
String formatLines = ThrowableFormatter.format(exception);
|
||||
String[] lines = formatLines.split("\n");
|
||||
Assert.assertEquals("java.lang.NullPointerException", lines[0]);
|
||||
Assert.assertEquals("\tat com.a.eye.skywalking.api.logging.ThrowableFormatterTest.testFormat(ThrowableFormatterTest.java:12)", lines[1]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import java.io.PrintStream;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class WriterFactoryTest {
|
||||
private static PrintStream errRef;
|
||||
|
||||
@BeforeClass
|
||||
public static void initAndHoldOut(){
|
||||
errRef = System.err;
|
||||
}
|
||||
|
||||
/**
|
||||
* During this test case,
|
||||
* reset {@link System#out} to a Mock object, for avoid a console system.error.
|
||||
*/
|
||||
@Test
|
||||
public void testGetLogWriter(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = true;
|
||||
PrintStream mockStream = Mockito.mock(PrintStream.class);
|
||||
System.setErr(mockStream);
|
||||
Assert.assertEquals(SyncFileWriter.instance(), WriterFactory.getLogWriter());
|
||||
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
Assert.assertTrue(WriterFactory.getLogWriter() instanceof STDOutWriter);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void reset(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
System.setErr(errRef);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.a.eye.skywalking.api.plugin.bytebuddy;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class AllObjectDefaultMethodsMatchTest {
|
||||
@Test
|
||||
public void testMatches(){
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.a.eye.skywalking.api.plugin.bytebuddy;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.method.ParameterDescription;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author wusheng
|
||||
*/
|
||||
public class ArgumentTypeNameMatchTest {
|
||||
@Test
|
||||
public void testMatches() throws IllegalAccessException {
|
||||
MethodDescription methodDescription = Mockito.mock(MethodDescription.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
ParameterDescription parameterDescription = Mockito.mock(ParameterDescription.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
when(methodDescription.getParameters().get(0)).thenReturn(parameterDescription);
|
||||
when(methodDescription.getParameters().size()).thenReturn(1);
|
||||
when(parameterDescription.getType().asErasure().getName()).thenReturn("com.a.eye.TestClass");
|
||||
|
||||
ArgumentTypeNameMatch matcher = ((ArgumentTypeNameMatch)ArgumentTypeNameMatch.takesArgumentWithType(0, "com.a.eye.TestClass"));
|
||||
Assert.assertTrue(matcher.matches(methodDescription));
|
||||
|
||||
ArgumentTypeNameMatch matcher2 = ((ArgumentTypeNameMatch)ArgumentTypeNameMatch.takesArgumentWithType(0, "com.a.eye.TestClass2"));
|
||||
Assert.assertFalse(matcher2.matches(methodDescription));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchesWithNoParameters(){
|
||||
MethodDescription methodDescription = Mockito.mock(MethodDescription.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
ParameterDescription parameterDescription = Mockito.mock(ParameterDescription.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
when(methodDescription.getParameters().size()).thenReturn(0);
|
||||
|
||||
ArgumentTypeNameMatch matcher2 = ((ArgumentTypeNameMatch)ArgumentTypeNameMatch.takesArgumentWithType(0, "com.a.eye.TestClass"));
|
||||
Assert.assertFalse(matcher2.matches(methodDescription));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
skywalking.username = testUser
|
||||
skywalking.application_code = crmApp
|
||||
skywalking.servers = 127.0.0.1:8080
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.trace.builders.span;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public abstract class SpanGeneration {
|
||||
private SpanGeneration next;
|
||||
|
||||
public SpanGeneration build(SpanGeneration next){
|
||||
this.next = next;
|
||||
return next;
|
||||
}
|
||||
|
||||
public SpanGeneration build(){
|
||||
return this;
|
||||
}
|
||||
|
||||
protected abstract void before();
|
||||
|
||||
protected abstract void after();
|
||||
|
||||
public void generate(){
|
||||
this.before();
|
||||
if(next != null){
|
||||
next.generate();
|
||||
}
|
||||
this.after();
|
||||
}
|
||||
}
|
||||
|
|
@ -9,45 +9,57 @@ import com.a.eye.skywalking.trace.tag.Tags;
|
|||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public enum TomcatSpanGenerator {
|
||||
INSTANCE;
|
||||
public class TomcatSpanGenerator{
|
||||
public static class ON200 extends SpanGeneration{
|
||||
public static final ON200 INSTANCE = new ON200();
|
||||
|
||||
/**
|
||||
* When tomcat response 200.
|
||||
*/
|
||||
public void on200(){
|
||||
Span webSpan = ContextManager.INSTANCE.createSpan("/web/serviceA");
|
||||
Tags.COMPONENT.set(webSpan, "tomcat");
|
||||
Tags.URL.set(webSpan, "http://10.21.9.35/web/serviceA");
|
||||
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
|
||||
Tags.STATUS_CODE.set(webSpan, 200);
|
||||
ContextManager.INSTANCE.stopSpan(webSpan);
|
||||
@Override protected void before() {
|
||||
Span webSpan = ContextManager.INSTANCE.createSpan("/web/serviceA");
|
||||
Tags.COMPONENT.set(webSpan, "tomcat");
|
||||
Tags.URL.set(webSpan, "http://10.21.9.35/web/serviceA");
|
||||
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
|
||||
}
|
||||
|
||||
@Override protected void after() {
|
||||
Span webSpan = ContextManager.INSTANCE.activeSpan();
|
||||
Tags.STATUS_CODE.set(webSpan, 200);
|
||||
ContextManager.INSTANCE.stopSpan();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When tomcat response 404.
|
||||
*/
|
||||
public void on404(){
|
||||
Span webSpan = ContextManager.INSTANCE.createSpan("/web/service/unknown");
|
||||
Tags.COMPONENT.set(webSpan, "tomcat");
|
||||
Tags.URL.set(webSpan, "http://10.21.9.35/web/unknown");
|
||||
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
|
||||
Tags.STATUS_CODE.set(webSpan, 404);
|
||||
Tags.ERROR.set(webSpan,true);
|
||||
ContextManager.INSTANCE.stopSpan(webSpan);
|
||||
}
|
||||
public static class ON404 extends SpanGeneration{
|
||||
public static final ON404 INSTANCE = new ON404();
|
||||
|
||||
/**
|
||||
* When tomcat response 500.
|
||||
*/
|
||||
public void on500(){
|
||||
Span webSpan = ContextManager.INSTANCE.createSpan("/web/error/service");
|
||||
Tags.COMPONENT.set(webSpan, "tomcat");
|
||||
Tags.URL.set(webSpan, "http://10.21.9.35/web/error/service");
|
||||
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
|
||||
Tags.STATUS_CODE.set(webSpan, 500);
|
||||
Tags.ERROR.set(webSpan,true);
|
||||
webSpan.log(new NumberFormatException("Can't convert 'abc' to int."));
|
||||
ContextManager.INSTANCE.stopSpan(webSpan);
|
||||
@Override protected void before() {
|
||||
Span webSpan = ContextManager.INSTANCE.createSpan("/web/service/unknown");
|
||||
Tags.COMPONENT.set(webSpan, "tomcat");
|
||||
Tags.URL.set(webSpan, "http://10.21.9.35/web/unknown");
|
||||
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
|
||||
}
|
||||
|
||||
@Override protected void after() {
|
||||
Span webSpan = ContextManager.INSTANCE.activeSpan();
|
||||
Tags.STATUS_CODE.set(webSpan, 404);
|
||||
Tags.ERROR.set(webSpan,true);
|
||||
ContextManager.INSTANCE.stopSpan();
|
||||
}
|
||||
}
|
||||
public static class ON500 extends SpanGeneration{
|
||||
public static final ON500 INSTANCE = new ON500();
|
||||
|
||||
@Override protected void before() {
|
||||
Span webSpan = ContextManager.INSTANCE.createSpan("/web/error/service");
|
||||
Tags.COMPONENT.set(webSpan, "tomcat");
|
||||
Tags.URL.set(webSpan, "http://10.21.9.35/web/error/service");
|
||||
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
|
||||
}
|
||||
|
||||
@Override protected void after() {
|
||||
Span webSpan = ContextManager.INSTANCE.activeSpan();
|
||||
Tags.STATUS_CODE.set(webSpan, 500);
|
||||
Tags.ERROR.set(webSpan,true);
|
||||
webSpan.log(new NumberFormatException("Can't convert 'abc' to int."));
|
||||
ContextManager.INSTANCE.stopSpan();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public enum SingleTomcat200TraceBuilder implements TraceSegmentBuilder {
|
|||
INSTANCE;
|
||||
|
||||
@Override public TraceSegment build(MockTracerContextListener listener) {
|
||||
TomcatSpanGenerator.INSTANCE.on200();
|
||||
TomcatSpanGenerator.ON200.INSTANCE.build().generate();
|
||||
return listener.getFinished(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public enum SingleTomcat404TraceBuilder implements TraceSegmentBuilder {
|
|||
INSTANCE;
|
||||
|
||||
@Override public TraceSegment build(MockTracerContextListener listener) {
|
||||
TomcatSpanGenerator.INSTANCE.on404();
|
||||
TomcatSpanGenerator.ON404.INSTANCE.build().generate();
|
||||
return listener.getFinished(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public enum SingleTomcat500TraceBuilder implements TraceSegmentBuilder {
|
|||
INSTANCE;
|
||||
|
||||
@Override public TraceSegment build(MockTracerContextListener listener) {
|
||||
TomcatSpanGenerator.INSTANCE.on500();
|
||||
TomcatSpanGenerator.ON500.INSTANCE.build().generate();
|
||||
return listener.getFinished(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package com.a.eye.skywalking.toolkit.activation.trace;
|
|||
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.logging.ILog;
|
||||
import com.a.eye.skywalking.api.logging.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.StaticMethodInvokeContext;
|
||||
|
|
|
|||
Loading…
Reference in New Issue