Skip to content

Commit

Permalink
add async trace
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Apr 1, 2015
1 parent be66819 commit 12ee80b
Show file tree
Hide file tree
Showing 34 changed files with 913 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ public interface RecordableTrace {
Object setAttribute(String key, Object value);

Object removeAttribute(String key);

void recordAsyncId(int asyncId);

void recordnextAsyncId(int asyncId);

boolean isAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface TraceContext {
Trace continueTraceObject(TraceId traceID);

Trace newTraceObject();

Trace continueAsyncTraceObject(TraceId traceId, int asyncId, long startTime);

void attachTraceObject(Trace trace);

Expand Down Expand Up @@ -84,5 +86,6 @@ public interface TraceContext {
void recordUserAcceptResponseTime(int elapsedTime);

ServerMetaDataHolder getServerMetaDataHolder();


int getAsyncId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,17 @@ public Object removeTraceBlockAttachment() {
this.attachment = null;
return copy;
}

@Override
public void recordAsyncId(int asyncId) {
}

@Override
public void recordnextAsyncId(int asyncId) {
}

@Override
public boolean isAsync() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,15 @@ public ServerMetaDataHolder getServerMetaDataHolder() {
@Override
public void attachTraceObject(Trace trace) {
}

@Override
public Trace continueAsyncTraceObject(TraceId traceId, int asyncId, long startTime) {
// TODO Auto-generated method stub
return null;
}

@Override
public int getAsyncId() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void addNestedSpanEvent(Put put, TSpan span) {
long acceptedTime0 = acceptedTimeService.getAcceptedTime();
for (TSpanEvent spanEvent : spanEventBoList) {
SpanEventBo spanEventBo = new SpanEventBo(span, spanEvent);
byte[] rowId = BytesUtils.add(spanEventBo.getSpanId(), spanEventBo.getSequence());
byte[] rowId = BytesUtils.add(spanEventBo.getSpanId(), spanEventBo.getSequence(), spanEventBo.getAsyncId());
byte[] value = spanEventBo.writeValue();
put.add(TRACES_CF_TERMINALSPAN, rowId, acceptedTime0, value);
}
Expand All @@ -128,7 +128,7 @@ public void insertSpanChunk(TSpanChunk spanChunk) {
SpanEventBo spanEventBo = new SpanEventBo(spanChunk, spanEvent);

byte[] value = spanEventBo.writeValue();
byte[] rowId = BytesUtils.add(spanEventBo.getSpanId(), spanEventBo.getSequence());
byte[] rowId = BytesUtils.add(spanEventBo.getSpanId(), spanEventBo.getSequence(), spanEventBo.getAsyncId());

put.add(TRACES_CF_TERMINALSPAN, rowId, acceptedTime, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public boolean isViewInRecordSet() {
public static final AnnotationKey EXCEPTION_CLASS = new AnnotationKey(-51, "ExceptionClass");
public static final AnnotationKey UNKNOWN = new AnnotationKey(-9999, "UNKNOWN");

public static final AnnotationKey ASYNC = new AnnotationKey(-100, "Asynchronous Invocation");

private final int code;
private final String name;
private final boolean viewInRecordSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

/**
* @author emeroad
* @author jaehong.kim
*/
public class SpanEventBo implements Span {
private static final int VERSION_SIZE = 1;
Expand Down Expand Up @@ -69,6 +70,8 @@ public class SpanEventBo implements Span {
// should get exceptionClass from dao
private String exceptionClass;

private int asyncId = -1;
private int nextAsyncId = -1;

public SpanEventBo() {
}
Expand Down Expand Up @@ -124,6 +127,14 @@ public SpanEventBo(TSpan tSpan, TSpanEvent tSpanEvent) {
this.exceptionId = exceptionInfo.getIntValue();
this.exceptionMessage = exceptionInfo.getStringValue();
}

if(tSpanEvent.isSetAsyncId()) {
this.asyncId = tSpanEvent.getAsyncId();
}

if(tSpanEvent.isSetNextAsyncId()) {
this.nextAsyncId = tSpanEvent.getNextAsyncId();
}
}

public SpanEventBo(TSpanChunk spanChunk, TSpanEvent spanEvent) {
Expand Down Expand Up @@ -176,6 +187,14 @@ public SpanEventBo(TSpanChunk spanChunk, TSpanEvent spanEvent) {
this.exceptionId = exceptionInfo.getIntValue();
this.exceptionMessage = exceptionInfo.getStringValue();
}

if(spanEvent.isSetAsyncId()) {
this.asyncId = spanEvent.getAsyncId();
}

if(spanEvent.isSetNextAsyncId()) {
this.nextAsyncId = spanEvent.getNextAsyncId();
}
}


Expand Down Expand Up @@ -359,7 +378,21 @@ public void setExceptionClass(String exceptionClass) {
this.exceptionClass = exceptionClass;
}

public int getAsyncId() {
return asyncId;
}

public void setAsyncId(int asyncId) {
this.asyncId = asyncId;
}

public int getNextAsyncId() {
return nextAsyncId;
}

public void setNextAsyncId(int nextAsyncId) {
this.nextAsyncId = nextAsyncId;
}

public byte[] writeValue() {
final Buffer buffer = new AutomaticBuffer(512);
Expand Down Expand Up @@ -397,20 +430,18 @@ public byte[] writeValue() {
}

writeAnnotation(buffer);

buffer.putSVar(nextAsyncId);

return buffer.getBuffer();
}



private void writeAnnotation(Buffer buffer) {
AnnotationBoList annotationBo = new AnnotationBoList(this.annotationBoList);
annotationBo.writeValue(buffer);
}


public int readValue(byte[] bytes, int offset) {
public int readValue(byte[] bytes, int offset, int length) {
final int endOffset = offset + length;
final Buffer buffer = new OffsetFixedBuffer(bytes, offset);

this.version = buffer.readByte();
Expand Down Expand Up @@ -445,6 +476,10 @@ public int readValue(byte[] bytes, int offset) {
}

this.annotationBoList = readAnnotation(buffer);
if(buffer.getOffset() < endOffset) {
nextAsyncId = buffer.readSVarInt();
}

return buffer.getOffset();
}

Expand All @@ -456,31 +491,58 @@ private List<AnnotationBo> readAnnotation(Buffer buffer) {

@Override
public String toString() {
final StringBuilder sb = new StringBuilder(256);
sb.append("SpanEventBo{");
sb.append("version=").append(version);
sb.append(", agentId='").append(agentId).append('\'');
sb.append(", applicationId='").append(applicationId).append('\'');
sb.append(", agentStartTime=").append(agentStartTime);
sb.append(", traceAgentId='").append(traceAgentId).append('\'');
sb.append(", traceAgentStartTime=").append(traceAgentStartTime);
sb.append(", traceTransactionSequence=").append(traceTransactionSequence);
sb.append(", spanId=").append(spanId);
sb.append(", sequence=").append(sequence);
sb.append(", startElapsed=").append(startElapsed);
sb.append(", endElapsed=").append(endElapsed);
sb.append(", rpc='").append(rpc).append('\'');
sb.append(", serviceType=").append(serviceType);
sb.append(", destinationId='").append(destinationId).append('\'');
sb.append(", endPoint='").append(endPoint).append('\'');
sb.append(", apiId=").append(apiId);
sb.append(", annotationBoList=").append(annotationBoList);
sb.append(", depth=").append(depth);
sb.append(", nextSpanId=").append(nextSpanId);
sb.append(", hasException=").append(hasException);
sb.append(", exceptionId=").append(exceptionId);
sb.append(", exceptionMessage='").append(exceptionMessage).append('\'');
sb.append('}');
return sb.toString();
StringBuilder builder = new StringBuilder();
builder.append("{version=");
builder.append(version);
builder.append(", agentId=");
builder.append(agentId);
builder.append(", applicationId=");
builder.append(applicationId);
builder.append(", agentStartTime=");
builder.append(agentStartTime);
builder.append(", traceAgentId=");
builder.append(traceAgentId);
builder.append(", traceAgentStartTime=");
builder.append(traceAgentStartTime);
builder.append(", traceTransactionSequence=");
builder.append(traceTransactionSequence);
builder.append(", spanId=");
builder.append(spanId);
builder.append(", sequence=");
builder.append(sequence);
builder.append(", startElapsed=");
builder.append(startElapsed);
builder.append(", endElapsed=");
builder.append(endElapsed);
builder.append(", rpc=");
builder.append(rpc);
builder.append(", serviceType=");
builder.append(serviceType);
builder.append(", destinationId=");
builder.append(destinationId);
builder.append(", endPoint=");
builder.append(endPoint);
builder.append(", apiId=");
builder.append(apiId);
builder.append(", annotationBoList=");
builder.append(annotationBoList);
builder.append(", depth=");
builder.append(depth);
builder.append(", nextSpanId=");
builder.append(nextSpanId);
builder.append(", hasException=");
builder.append(hasException);
builder.append(", exceptionId=");
builder.append(exceptionId);
builder.append(", exceptionMessage=");
builder.append(exceptionMessage);
builder.append(", exceptionClass=");
builder.append(exceptionClass);
builder.append(", asyncId=");
builder.append(asyncId);
builder.append(", nextAsyncId=");
builder.append(nextAsyncId);
builder.append("}");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ public static byte[] add(final long preFix, final short postFix) {
writeShort(postFix, buf, 8);
return buf;
}

public static byte[] add(final long preFix, final short postFix, final int append) {
byte[] buf = new byte[LONG_BYTE_LENGTH + SHORT_BYTE_LENGTH + INT_BYTE_LENGTH];
writeLong(preFix, buf, 0);
writeShort(postFix, buf, LONG_BYTE_LENGTH);
writeInt(append, buf, LONG_BYTE_LENGTH + SHORT_BYTE_LENGTH);
return buf;
}


public static byte[] toBytes(final String value) {
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testSerialize() throws Exception {
byte[] bytes = spanEventBo.writeValue();

SpanEventBo newSpanEventBo = new SpanEventBo();
int i = newSpanEventBo.readValue(bytes, 0);
int i = newSpanEventBo.readValue(bytes, 0, bytes.length);
Assert.assertEquals(bytes.length, i);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package com.navercorp.pinpoint.plugin.httpclient4;

import static com.navercorp.pinpoint.common.HistogramSchema.FAST_SCHEMA;
import static com.navercorp.pinpoint.common.HistogramSchema.NORMAL_SCHEMA;
import static com.navercorp.pinpoint.common.ServiceTypeProperty.RECORD_STATISTICS;
import static com.navercorp.pinpoint.common.ServiceTypeProperty.TERMINAL;

import com.navercorp.pinpoint.common.ServiceType;

Expand All @@ -29,11 +27,13 @@
*/
public interface HttpClient4Constants {

public static final ServiceType HTTP_CLIENT4 = ServiceType.of(9052, "HTTP_CLIENT", NORMAL_SCHEMA, RECORD_STATISTICS);
public static final ServiceType HTTP_CLIENT4_INTERNAL = ServiceType.of(9053, "HTTP_CLIENT_INTERNAL", "HTTP_CLIENT", NORMAL_SCHEMA);
public static final ServiceType HTTP_CLIENT4 = ServiceType.of(9052, "HTTP_CLIENT4", NORMAL_SCHEMA, RECORD_STATISTICS);
public static final ServiceType HTTP_CLIENT4_INTERNAL = ServiceType.of(9053, "HTTP_CLIENT4_INTERNAL", "HTTP_CLIENT", NORMAL_SCHEMA);

public static final String METADATA_END_POINT = "endPoint";
public static final String METADATA_DESTINATION_ID = "destinationId";
public static final String METADATA_ASYNC_TRACE_ID = "asyncTraceId";


public static final String HTTP_CLIENT4_SCOPE = "HttpClient4Scope";
}
Loading

0 comments on commit 12ee80b

Please sign in to comment.