将魔法字符挪成常量
This commit is contained in:
parent
0060a132e4
commit
9c3a9560f4
|
|
@ -2,5 +2,11 @@ package com.ai.cloud.skywalking.constants;
|
|||
|
||||
public class Constants {
|
||||
|
||||
public static final String spiltRegx = "^~";
|
||||
public static final String SPAN_FIELD_SPILT_PATTERN = "^~";
|
||||
|
||||
public static final String BUSINESSKEY_SPILT_PATTERN = "~^";
|
||||
|
||||
public static final String NEW_LINE_CHARACTER_PATTERN = "\\n";
|
||||
|
||||
public static final String EXCEPTION_SPILT_PATTERN = "^";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,53 +134,54 @@ public class Span {
|
|||
@Override
|
||||
public String toString() {
|
||||
StringBuilder toStringValue = new StringBuilder();
|
||||
toStringValue.append(traceId + Constants.spiltRegx);
|
||||
toStringValue.append(traceId + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
|
||||
if (!StringUtil.isEmpty(parentLevel)) {
|
||||
toStringValue.append(parentLevel + Constants.spiltRegx);
|
||||
toStringValue.append(parentLevel + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
} else {
|
||||
toStringValue.append(" " + Constants.spiltRegx);
|
||||
toStringValue.append(" " + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
}
|
||||
|
||||
toStringValue.append(levelId + Constants.spiltRegx);
|
||||
toStringValue.append(levelId + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
|
||||
if (!StringUtil.isEmpty(viewPointId)) {
|
||||
toStringValue.append(viewPointId + Constants.spiltRegx);
|
||||
toStringValue.append(viewPointId + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
} else {
|
||||
toStringValue.append(" " + Constants.spiltRegx);
|
||||
toStringValue.append(" " + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
}
|
||||
|
||||
toStringValue.append(startDate + Constants.spiltRegx);
|
||||
toStringValue.append(cost + Constants.spiltRegx);
|
||||
toStringValue.append(startDate + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
toStringValue.append(cost + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
|
||||
if (!StringUtil.isEmpty(address)) {
|
||||
toStringValue.append(address + Constants.spiltRegx);
|
||||
toStringValue.append(address + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
} else {
|
||||
toStringValue.append(" " + Constants.spiltRegx);
|
||||
toStringValue.append(" " + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
}
|
||||
|
||||
toStringValue.append(statusCode + Constants.spiltRegx);
|
||||
toStringValue.append(statusCode + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
|
||||
if (!StringUtil.isEmpty(exceptionStack)) {
|
||||
toStringValue.append(exceptionStack + Constants.spiltRegx);
|
||||
toStringValue.append(exceptionStack + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
} else {
|
||||
toStringValue.append(" " + Constants.spiltRegx);
|
||||
toStringValue.append(" " + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
}
|
||||
|
||||
toStringValue.append(spanType + Constants.spiltRegx);
|
||||
toStringValue.append(isReceiver + Constants.spiltRegx);
|
||||
toStringValue.append(spanType + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
toStringValue.append(isReceiver + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
|
||||
|
||||
if (!StringUtil.isEmpty(businessKey)) {
|
||||
toStringValue.append(businessKey + Constants.spiltRegx);
|
||||
toStringValue.append(businessKey.replaceAll(Constants.NEW_LINE_CHARACTER_PATTERN,
|
||||
Constants.BUSINESSKEY_SPILT_PATTERN) + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
} else {
|
||||
toStringValue.append(" " + Constants.spiltRegx);
|
||||
toStringValue.append(" " + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
}
|
||||
|
||||
if (!StringUtil.isEmpty(processNo)) {
|
||||
toStringValue.append(processNo);
|
||||
} else {
|
||||
toStringValue.append(" " + Constants.spiltRegx);
|
||||
toStringValue.append(" " + Constants.SPAN_FIELD_SPILT_PATTERN);
|
||||
}
|
||||
|
||||
return toStringValue.toString();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ai.cloud.skywalking.util;
|
||||
|
||||
import com.ai.cloud.skywalking.constants.Constants;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.context.Span;
|
||||
|
||||
|
|
@ -21,13 +22,14 @@ public final class ExceptionHandleUtil {
|
|||
try {
|
||||
buf.close();
|
||||
} catch (IOException e1) {
|
||||
expMessage.append("\n本地发送埋点关闭异常读入流异常,异常信息:");
|
||||
expMessage.append("\nClose exception stack input stream failed:\n");
|
||||
expMessage.append(e1.getCause().getMessage());
|
||||
}
|
||||
if (expMessage.length() <= MAX_EXCEPTION_STACK_LENGTH) {
|
||||
return expMessage.toString().replaceAll("\\n", "^");
|
||||
return expMessage.toString().replaceAll(Constants.NEW_LINE_CHARACTER_PATTERN, Constants.EXCEPTION_SPILT_PATTERN);
|
||||
} else {
|
||||
return expMessage.toString().replaceAll("\\n", "^").substring(0, MAX_EXCEPTION_STACK_LENGTH);
|
||||
return expMessage.toString().replaceAll(Constants.NEW_LINE_CHARACTER_PATTERN, Constants.EXCEPTION_SPILT_PATTERN)
|
||||
.substring(0, MAX_EXCEPTION_STACK_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue