use of com.navercorp.pinpoint.common.server.bo.SpanBo in project pinpoint by naver.
the class SpanMapperV2Test method test.
@Test
public void test() {
SpanBo span = new SpanBo();
span.setServiceType((short) 1000);
span.setExceptionInfo(1, "spanException");
SpanEventBo firstSpanEventBo = new SpanEventBo();
firstSpanEventBo.setExceptionInfo(2, "first");
firstSpanEventBo.setEndElapsed(100);
AnnotationBo annotationBo = newAnnotation(200, "annotation");
firstSpanEventBo.setAnnotationBoList(Lists.<AnnotationBo>newArrayList(annotationBo));
firstSpanEventBo.setServiceType((short) 1003);
firstSpanEventBo.setSequence((short) 0);
span.addSpanEvent(firstSpanEventBo);
//// next
SpanEventBo nextSpanEventBo = new SpanEventBo();
nextSpanEventBo.setEndElapsed(200);
nextSpanEventBo.setServiceType((short) 2003);
nextSpanEventBo.setSequence((short) 1);
span.addSpanEvent(nextSpanEventBo);
SpanEncodingContext<SpanBo> encodingContext = new SpanEncodingContext<>(span);
SpanEncoder encoder = new SpanEncoderV0();
ByteBuffer byteBuffer = encoder.encodeSpanColumnValue(encodingContext);
Buffer buffer = new OffsetFixedBuffer(byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.remaining());
SpanBo readSpan = new SpanBo();
SpanDecodingContext decodingContext = new SpanDecodingContext();
decoder.readSpanValue(buffer, readSpan, new SpanEventBo(), decodingContext);
Assert.assertEquals(readSpan.getSpanEventBoList().size(), 2);
// span
Assert.assertEquals(readSpan.getServiceType(), 1000);
Assert.assertEquals(readSpan.hasException(), true);
Assert.assertEquals(readSpan.getExceptionId(), 1);
Assert.assertEquals(readSpan.getExceptionMessage(), "spanException");
List<SpanEventBo> spanEventBoList = readSpan.getSpanEventBoList();
SpanEventBo readFirst = spanEventBoList.get(0);
SpanEventBo readNext = spanEventBoList.get(1);
Assert.assertEquals(readFirst.getEndElapsed(), 100);
Assert.assertEquals(readNext.getEndElapsed(), 200);
Assert.assertEquals(readFirst.getExceptionId(), 2);
Assert.assertEquals(readNext.hasException(), false);
Assert.assertEquals(readFirst.getServiceType(), 1003);
Assert.assertEquals(readNext.getServiceType(), 2003);
Assert.assertEquals(readFirst.getSequence(), 0);
Assert.assertEquals(readNext.getSequence(), 1);
}
use of com.navercorp.pinpoint.common.server.bo.SpanBo in project pinpoint by naver.
the class StandardHostValveInvokeModifierTest method invokeShouldBeTraced.
@Test
@IsRootSpan
public void invokeShouldBeTraced() throws Exception {
// Given
// When
host.invoke(mockRequest, mockResponse);
// Then
final List<SpanBo> rootSpans = getCurrentRootSpans();
assertEquals(rootSpans.size(), 1);
final SpanBo rootSpan = rootSpans.get(0);
assertEquals(rootSpan.getParentSpanId(), -1);
assertEquals(rootSpan.getServiceType(), SERVICE_TYPE.getCode());
assertEquals(rootSpan.getRpc(), REQUEST_URI);
assertEquals(rootSpan.getEndPoint(), SERVER_NAME + ":" + SERVER_PORT);
assertEquals(rootSpan.getRemoteAddr(), REMOTE_ADDRESS);
}
use of com.navercorp.pinpoint.common.server.bo.SpanBo in project pinpoint by naver.
the class StandardHostValveInvokeModifierTest method invokeShouldContinueTracingFromRequest.
@Test
@IsRootSpan
public void invokeShouldContinueTracingFromRequest() throws Exception {
// Given
// Set Transaction ID from remote source.
final String sourceAgentId = "agentId";
final long sourceAgentStartTime = 1234567890123L;
final long sourceTransactionSequence = 12345678L;
final String sourceTransactionId = TransactionIdUtils.formatString(sourceAgentId, sourceAgentStartTime, sourceTransactionSequence);
when(mockRequest.getHeader(Header.HTTP_TRACE_ID.toString())).thenReturn(sourceTransactionId);
// Set parent Span ID from remote source.
final long sourceParentId = 99999;
when(mockRequest.getHeader(Header.HTTP_PARENT_SPAN_ID.toString())).thenReturn(String.valueOf(sourceParentId));
// When
host.invoke(mockRequest, mockResponse);
// Then
final List<SpanBo> rootSpans = getCurrentRootSpans();
assertEquals(rootSpans.size(), 1);
final SpanBo rootSpan = rootSpans.get(0);
// Check Transaction ID from remote source.
assertEquals(TransactionIdUtils.formatString(rootSpan.getTransactionId()), sourceTransactionId);
assertEquals(rootSpan.getTransactionId().getAgentId(), sourceAgentId);
assertEquals(rootSpan.getTransactionId().getAgentStartTime(), sourceAgentStartTime);
assertEquals(rootSpan.getTransactionId().getTransactionSequence(), sourceTransactionSequence);
// Check parent Span ID from remote source.
assertEquals(rootSpan.getParentSpanId(), sourceParentId);
}
use of com.navercorp.pinpoint.common.server.bo.SpanBo in project pinpoint by naver.
the class BasePinpointTest method getCurrentRootSpans.
protected List<SpanBo> getCurrentRootSpans() {
List<SpanBo> rootSpans = new ArrayList<SpanBo>();
for (TBase<?, ?> span : this.tBaseRecorder) {
if (span instanceof Span) {
SpanBo spanBo = spanFactory.buildSpanBo((Span) span);
rootSpans.add(spanBo);
}
}
return rootSpans;
}
use of com.navercorp.pinpoint.common.server.bo.SpanBo in project pinpoint by naver.
the class SpanAligner2 method findRootSpanId.
private long findRootSpanId(List<SpanBo> spanList, long collectorAcceptTime) {
if (spanList == null) {
throw new NullPointerException("spanList must not be null");
}
final List<SpanBo> root = new ArrayList<>();
for (SpanBo span : spanList) {
if (span.getParentSpanId() == ROOT) {
root.add(span);
}
}
// perfect match condition
final int rootSpanBoSize = root.size();
if (rootSpanBoSize == 1) {
final SpanBo spanBo = root.get(0);
logger.debug("root span found. best match:{}", spanBo);
matchType = BEST_MATCH;
// XXX in case where root exist but no span queried. additional logic needed
return spanBo.getSpanId();
}
// XXX: a bug in the logic if rootspan is more than 2. should we display randomly?
if (rootSpanBoSize > 1) {
logger.warn("parentSpanId(-1) collision. size:{} root span:{} allSpan:{}", rootSpanBoSize, root, spanList);
throw new IllegalStateException("parentSpanId(-1) collision. size:" + rootSpanBoSize);
}
// missing root or incomplete root (not arrived yet): meaning on-going process
// next best thing is to lookup span based on the beginning of time of span it looked up
// most likely data exist since the data gets extracted from span. non-existent data possible due to hbase insertion failure
final List<SpanBo> collectorAcceptTimeMatcher = new ArrayList<>();
for (SpanBo span : spanList) {
// collectorTime is a hint
if (span.getCollectorAcceptTime() == collectorAcceptTime) {
collectorAcceptTimeMatcher.add(span);
}
}
// a match based on startTime. a more accurate matching is possible when additional information is given (see below)
// which one of these leads to a best match? probably agentId.
// "applicationName" : "/httpclient4/post.pinpoint",
// "transactionId" : "emeroad-pc^1382955966412^16",
// "agentId" : "emeroad-pc",
// "applicationId" : "emeroad-app",
// "callStackStart" : 1383024213315,
// "callStackEnd" : 2010,
final int startMatchSize = collectorAcceptTimeMatcher.size();
if (startMatchSize == 1) {
final SpanBo spanBo = collectorAcceptTimeMatcher.get(0);
logger.info("collectorAcceptTime span found startTime match:{}", spanBo);
matchType = START_TIME_MATCH;
return spanBo.getSpanId();
}
if (startMatchSize > 1) {
logger.warn("collectorAcceptTime match collision. size:{} collectorAcceptTime:{} allSpan:{}", startMatchSize, collectorAcceptTime, spanList);
throw new IllegalStateException("startTime match collision size:" + startMatchSize + " collectorAcceptTime:" + collectorAcceptTime);
}
// can we do better? There doesn't seem to be a definitive answer for rendering the call stack
logger.warn("collectorAcceptTime match not found. size:{} collectorAcceptTime:{} allSpan:{}", startMatchSize, collectorAcceptTime, spanList);
throw new IllegalStateException("startTime match not found startTime size:" + startMatchSize + " collectorAcceptTime:" + collectorAcceptTime);
}
Aggregations