1.增加SpanData的注释。详细描述每个属性的业务含义。

2.修改部分类名。
This commit is contained in:
wusheng 2016-01-28 11:32:32 +08:00
parent 89d01ee993
commit 221378d365
8 changed files with 127 additions and 50 deletions

View File

@ -29,7 +29,7 @@ public class Span extends SpanData {
}
public Span(String originData) {
String[] fieldValues = originData.split(SPAN_FIELD_SPILT_PATTERN);
String[] fieldValues = originData.split(SPAN_FIELD_SEPARATOR);
int index = 0;
while (this.setValueByIndex(fieldValues, index)) {
@ -67,7 +67,7 @@ public class Span extends SpanData {
break;
case 8:
exceptionStack = fieldValues[8].trim().replaceAll(
SPAN_ATTR_SPILT_CHARACTER, NEW_LINE_CHARACTER_PATTERN);
NEW_LINE_PLACEHOLDER, OS_NEW_LINE);
break;
case 9:
spanType = fieldValues[9];
@ -77,7 +77,7 @@ public class Span extends SpanData {
break;
case 11:
businessKey = fieldValues[11].trim().replaceAll(
SPAN_ATTR_SPILT_CHARACTER, NEW_LINE_CHARACTER_PATTERN);
NEW_LINE_PLACEHOLDER, OS_NEW_LINE);
break;
case 12:
processNo = fieldValues[12].trim();
@ -104,76 +104,76 @@ public class Span extends SpanData {
@Override
public String toString() {
StringBuilder toStringValue = new StringBuilder();
toStringValue.append(traceId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(traceId + SPAN_FIELD_SEPARATOR);
if (isNonBlank(parentLevel)) {
toStringValue.append(parentLevel + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(parentLevel + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(levelId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(levelId + SPAN_FIELD_SEPARATOR);
if (isNonBlank(viewPointId)) {
toStringValue.append(viewPointId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(viewPointId + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(startDate + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(cost + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(startDate + SPAN_FIELD_SEPARATOR);
toStringValue.append(cost + SPAN_FIELD_SEPARATOR);
if (isNonBlank(address)) {
toStringValue.append(address + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(address + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(statusCode + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(statusCode + SPAN_FIELD_SEPARATOR);
if (isNonBlank(exceptionStack)) {
// 换行符在各个系统中表现不一致
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue.append(exceptionStack.replaceAll(
CARRIAGE_RETURN_CHARACTER_PATTERN, "").replaceAll(
NEW_LINE_CHARACTER_PATTERN, SPAN_ATTR_SPILT_CHARACTER)
+ SPAN_FIELD_SPILT_PATTERN);
WINDOWS_OS_NEW_LINE_REDUNDANT_CHAR, "").replaceAll(
OS_NEW_LINE, NEW_LINE_PLACEHOLDER)
+ SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(spanType + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(isReceiver + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(spanType + SPAN_FIELD_SEPARATOR);
toStringValue.append(isReceiver + SPAN_FIELD_SEPARATOR);
if (isNonBlank(businessKey)) {
// 换行符在各个系统中表现不一致
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue.append(businessKey.replaceAll(
CARRIAGE_RETURN_CHARACTER_PATTERN, "").replaceAll(
NEW_LINE_CHARACTER_PATTERN, SPAN_ATTR_SPILT_CHARACTER)
+ SPAN_FIELD_SPILT_PATTERN);
WINDOWS_OS_NEW_LINE_REDUNDANT_CHAR, "").replaceAll(
OS_NEW_LINE, NEW_LINE_PLACEHOLDER)
+ SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
if (isNonBlank(processNo)) {
toStringValue.append(processNo + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(processNo + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
if (isNonBlank(applicationId)) {
toStringValue.append(applicationId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(applicationId + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
if (isNonBlank(userId)) {
toStringValue.append(userId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(userId + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(callType);

View File

@ -1,28 +1,105 @@
package com.ai.cloud.skywalking.protocol;
public abstract class SpanData {
/**
* Span在序列中各字段间的分隔符
*/
protected static final String SPAN_FIELD_SEPARATOR = "@~";
/**
* Span在序列化中新的换行符
*/
protected static final String NEW_LINE_PLACEHOLDER = "#~";
/**
* 字符串中的换行符
*/
protected static final String OS_NEW_LINE = "\n";
/**
* windows操作系统的多余换行字符
*/
protected static final String WINDOWS_OS_NEW_LINE_REDUNDANT_CHAR = "\r";
protected static final String SPAN_FIELD_SPILT_PATTERN = "@~";
protected static final String SPAN_ATTR_SPILT_CHARACTER = "#~";
protected static final String NEW_LINE_CHARACTER_PATTERN = "\n";
protected static final String CARRIAGE_RETURN_CHARACTER_PATTERN = "\r";
/**
* tid调用链的全局唯一标识
*/
protected String traceId;
/**
* 当前调用链的上级描述<br/>
* 如当前序号为0.1.0时parentLevel=0.1
*/
protected String parentLevel;
/**
* 当前调用链的本机描述<br/>
* 如当前序号为0.1.0时levelId=0
*/
protected int levelId = 0;
/**
* 调用链中单个节点的入口描述<br/>
* java方法名调用的RPC地址等等
*/
protected String viewPointId = "";
/**
* 节点调用开始时间
*/
protected long startDate = System.currentTimeMillis();
/**
* 节点调用花费时间
*/
protected long cost = 0L;
/**
* 节点调用的发生机器描述<br/>
* 包含机器名 + IP地址
*/
protected String address = "";
/**
* 节点调用的状态<br/>
* 0成功<br/>
* 1异常<br/>
* 异常判断原则代码产生exception并且此exception不在忽略列表中
*/
protected byte statusCode = 0;
/**
* 节点调用的错误堆栈<br/>
* 堆栈以JAVA的exception为主要判断依据
*/
protected String exceptionStack;
/**
* 节点类型描述<br/>
* 已字符串的形式描述<br/>
* java,dubbo等
*/
protected String spanType = "";
/**
* 节点调用类型描述<br/>
* @see com.ai.cloud.skywalking.protocol.CallType
*/
protected String callType = "";
/**
* 节点分布式类型<br/>
* 服务端/客户端
*/
protected boolean isReceiver = false;
/**
* 节点调用过程中的业务字段<br/>
* 业务系统设置的订单号SQL语句等
*/
protected String businessKey = "";
/**
* 节点调用的所在进程号
*/
protected String processNo = "";
/**
* 节点调用所在的系统逻辑名称<br/>
* 由授权文件指定
*/
protected String applicationId = "";
/**
* 反序列化时存储序列化前的字符串原文
*/
protected String originData = "";
/**
* 用户id<br/>
* 由授权文件指定
*/
protected String userId;

View File

@ -20,7 +20,7 @@ public class HttpClientTracing {
httpRequest.setHeader(traceHearName,
"ContextData=" + sender.beforeSend(Identification.newBuilder()
.viewPoint(url)
.spanType(WEBBuriedPointType.instance())
.spanType(WebBuriedPointType.instance())
.build())
.toString());
return executor.execute();

View File

@ -3,13 +3,13 @@ package com.ai.cloud.skywalking.plugin.httpclient.v42x;
import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.protocol.CallType;
public class WEBBuriedPointType implements IBuriedPointType {
public class WebBuriedPointType implements IBuriedPointType {
private static WEBBuriedPointType webBuriedPointType;
private static WebBuriedPointType webBuriedPointType;
public static IBuriedPointType instance() {
if (webBuriedPointType == null) {
webBuriedPointType = new WEBBuriedPointType();
webBuriedPointType = new WebBuriedPointType();
}
return webBuriedPointType;
@ -25,7 +25,7 @@ public class WEBBuriedPointType implements IBuriedPointType {
return CallType.SYNC;
}
private WEBBuriedPointType() {
private WebBuriedPointType() {
// Non
}
}

View File

@ -20,7 +20,7 @@ public class HttpClientTracing {
httpRequest.setHeader(traceHearName,
"ContextData=" + sender.beforeSend(Identification.newBuilder()
.viewPoint(url)
.spanType(WEBBuriedPointType.instance())
.spanType(WebBuriedPointType.instance())
.build())
.toString());
return executor.execute();

View File

@ -3,13 +3,13 @@ package com.ai.cloud.skywalking.plugin.httpclient.v43x;
import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.protocol.CallType;
public class WEBBuriedPointType implements IBuriedPointType {
public class WebBuriedPointType implements IBuriedPointType {
private static WEBBuriedPointType webBuriedPointType;
private static WebBuriedPointType webBuriedPointType;
public static IBuriedPointType instance() {
if (webBuriedPointType == null) {
webBuriedPointType = new WEBBuriedPointType();
webBuriedPointType = new WebBuriedPointType();
}
return webBuriedPointType;
@ -25,7 +25,7 @@ public class WEBBuriedPointType implements IBuriedPointType {
return CallType.SYNC;
}
private WEBBuriedPointType() {
private WebBuriedPointType() {
// Non
}
}

View File

@ -70,7 +70,7 @@ public class SkyWalkingFilter implements Filter {
private Identification generateIdentification(HttpServletRequest request) {
return Identification.newBuilder()
.viewPoint(request.getRequestURL().toString())
.spanType(WEBBuriedPointType.instance())
.spanType(WebBuriedPointType.instance())
.build();
}

View File

@ -3,13 +3,13 @@ package com.ai.cloud.skywalking.plugin.web;
import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.protocol.CallType;
public class WEBBuriedPointType implements IBuriedPointType {
public class WebBuriedPointType implements IBuriedPointType {
private static WEBBuriedPointType webBuriedPointType;
private static WebBuriedPointType webBuriedPointType;
public static IBuriedPointType instance() {
if (webBuriedPointType == null) {
webBuriedPointType = new WEBBuriedPointType();
webBuriedPointType = new WebBuriedPointType();
}
return webBuriedPointType;
@ -25,7 +25,7 @@ public class WEBBuriedPointType implements IBuriedPointType {
return CallType.SYNC;
}
private WEBBuriedPointType() {
private WebBuriedPointType() {
// Non
}
}