[유치수] [NOBTS] add exception property to span

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@1068 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Chisu Yu
2012-12-27 09:37:36 +00:00
parent 939610042e
commit c0f37afa59
3 changed files with 49 additions and 19 deletions
+13 -2
View File
@@ -20,11 +20,13 @@ public class Span implements Thriftable {
private String rpc;
private ServiceType serviceType;
private String endPoint;
private boolean exception;
private final List<HippoAnnotation> annotations = new ArrayList<HippoAnnotation>(5);
private List<SubSpan> subSpanList;
public Span(TraceID traceId) {
this.traceID = traceId;
}
@@ -96,8 +98,16 @@ public class Span implements Thriftable {
public void setSubSpanList(List<SubSpan> subSpanList) {
this.subSpanList = subSpanList;
}
public boolean isException() {
return exception;
}
public String toString() {
public void setException(boolean exception) {
this.exception = exception;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
@@ -108,7 +118,7 @@ public class Span implements Thriftable {
sb.append(", ServiceName = ").append(serviceName);
sb.append(", ServiceType = ").append(serviceType);
sb.append(", EndPoint = ").append(endPoint);
sb.append(", Exception = ").append(exception);
sb.append(",\n\t Annotations = {");
for (HippoAnnotation a : annotations) {
sb.append("\n\t\t").append(a);
@@ -134,6 +144,7 @@ public class Span implements Thriftable {
span.setSpanId(traceID.getSpanId());
span.setParentSpanId(traceID.getParentSpanId());
span.setEndPoint(endPoint);
span.setErr(exception);
// 여기서 데이터 인코딩을 하자.
List<com.profiler.common.dto.thrift.Annotation> annotationList = new ArrayList<com.profiler.common.dto.thrift.Annotation>(annotations.size());
@@ -23,7 +23,8 @@ public class SubSpan implements Thriftable {
private String rpc;
private ServiceType serviceType;
private String endPoint;
private boolean exception;
private final List<HippoAnnotation> annotations = new ArrayList<HippoAnnotation>(5);
public SubSpan(Span parentSpan) {
@@ -101,8 +102,16 @@ public class SubSpan implements Thriftable {
public void setServiceType(ServiceType serviceType) {
this.serviceType = serviceType;
}
public boolean isException() {
return exception;
}
public String toString() {
public void setException(boolean exception) {
this.exception = exception;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
@@ -114,6 +123,7 @@ public class SubSpan implements Thriftable {
sb.append(", ServiceName=").append(serviceName);
sb.append(", ServiceType=").append(serviceType);
sb.append(", EndPoint=").append(endPoint);
sb.append(", Exception=").append(exception);
sb.append(", Seq=").append(sequence);
sb.append(",\n\t Annotations = {");
for (HippoAnnotation a : annotations) {
@@ -133,7 +143,6 @@ public class SubSpan implements Thriftable {
public com.profiler.common.dto.thrift.SubSpan toThrift(boolean child) {
com.profiler.common.dto.thrift.SubSpan subSpan = new com.profiler.common.dto.thrift.SubSpan();
long parentSpanStartTime = parentSpan.getStartTime();
subSpan.setStartElapsed((int) (startTime - parentSpanStartTime));
subSpan.setEndElapsed((int) (endTime - startTime));
@@ -148,13 +157,11 @@ public class SubSpan implements Thriftable {
subSpan.setSpanId(parentSpanTraceID.getSpanId());
}
subSpan.setRpc(rpc);
subSpan.setServiceName(serviceName);
subSpan.setServiceType(serviceType.getCode());
subSpan.setEndPoint(endPoint);
subSpan.setErr(exception);
// 여기서 데이터 인코딩을 하자.
List<com.profiler.common.dto.thrift.Annotation> annotationList = new ArrayList<com.profiler.common.dto.thrift.Annotation>(annotations.size());
+23 -11
View File
@@ -3,6 +3,7 @@ package com.profiler.context;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.profiler.common.AnnotationNames;
import com.profiler.common.ServiceType;
import com.profiler.interceptor.MethodDescriptor;
import com.profiler.sender.DataSender;
@@ -211,6 +212,7 @@ public final class Trace {
}
}
@Deprecated
public void record(Annotation annotation) {
if (!tracingEnabled)
return;
@@ -218,38 +220,48 @@ public final class Trace {
annotate(annotation.getCode());
}
public void recordException(Object result) {
if (result instanceof Throwable) {
Throwable th = (Throwable) result;
recordAttribute("Exception", th.getMessage());
}
}
public void recordException(Object result) {
if (result instanceof Throwable) {
Throwable th = (Throwable) result;
recordAttribute(AnnotationNames.EXCEPTION, th.getMessage());
try {
StackFrame currentStackFrame = getCurrentStackFrame();
if (currentStackFrame instanceof RootStackFrame) {
((RootStackFrame) currentStackFrame).getSpan().setException(true);
} else {
((SubStackFrame) currentStackFrame).getSubSpan().setException(true);
}
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
public void recordApi(MethodDescriptor methodDescriptor) {
if (methodDescriptor == null) {
return;
}
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
recordAttribute("API", method);
recordAttribute(AnnotationNames.API, method);
}
public void recordApi(MethodDescriptor methodDescriptor, Object[] args) {
// API 저장 방법의 개선 필요.
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
recordAttribute("API", method);
recordAttribute(AnnotationNames.API, method);
recocordArgs(args);
}
public void recordApi(int apiId) {
recordAttribute("API-ID", apiId);
recordAttribute(AnnotationNames.API_ID, apiId);
}
public void recordApi(int apiId, Object[] args) {
recordAttribute("API-ID", apiId);
recordAttribute(AnnotationNames.API_ID, apiId);
recocordArgs(args);
}
private void recocordArgs(Object[] args) {
if (args != null) {
for (int i = 0; i < args.length; i++) {