use of org.apache.skywalking.apm.network.proto.TraceSegmentReference in project incubator-skywalking by apache.
the class ContextManagerTest method testTransform.
@Test
public void testTransform() throws InvalidProtocolBufferException {
ContextCarrier contextCarrier = new ContextCarrier().deserialize("1.234.1983829|3|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|1.2343.234234234");
assertTrue(contextCarrier.isValid());
AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier);
firstEntrySpan.setComponent(ComponentsDefine.TOMCAT);
Tags.HTTP.METHOD.set(firstEntrySpan, "GET");
Tags.URL.set(firstEntrySpan, "127.0.0.1:8080");
SpanLayer.asHttp(firstEntrySpan);
AbstractSpan secondEntrySpan = ContextManager.createEntrySpan("/testSecondEntry", contextCarrier);
secondEntrySpan.setComponent(ComponentsDefine.DUBBO);
Tags.URL.set(firstEntrySpan, "dubbo://127.0.0.1:8080");
SpanLayer.asRPCFramework(secondEntrySpan);
ContextCarrier injectContextCarrier = new ContextCarrier();
AbstractSpan exitSpan = ContextManager.createExitSpan("/textExitSpan", injectContextCarrier, "127.0.0.1:12800");
exitSpan.errorOccurred();
exitSpan.log(new RuntimeException("exception"));
exitSpan.setComponent(ComponentsDefine.HTTPCLIENT);
SpanLayer.asHttp(exitSpan);
ContextManager.stopSpan();
ContextManager.stopSpan();
ContextManager.stopSpan();
TraceSegment actualSegment = tracingData.getTraceSegments().get(0);
UpstreamSegment upstreamSegment = actualSegment.transform();
assertThat(upstreamSegment.getGlobalTraceIdsCount(), is(1));
TraceSegmentObject traceSegmentObject = TraceSegmentObject.parseFrom(upstreamSegment.getSegment());
TraceSegmentReference reference = traceSegmentObject.getSpans(1).getRefs(0);
assertThat(reference.getEntryServiceName(), is("/portal/"));
assertThat(reference.getNetworkAddress(), is("127.0.0.1:8080"));
assertThat(reference.getParentSpanId(), is(3));
assertThat(traceSegmentObject.getApplicationId(), is(1));
assertThat(traceSegmentObject.getSpans(1).getRefsCount(), is(1));
assertThat(traceSegmentObject.getSpansCount(), is(2));
SpanObject actualSpan = traceSegmentObject.getSpans(1);
assertThat(actualSpan.getComponentId(), is(3));
assertThat(actualSpan.getComponent(), is(""));
assertThat(actualSpan.getOperationName(), is("/testSecondEntry"));
assertThat(actualSpan.getParentSpanId(), is(-1));
assertThat(actualSpan.getSpanId(), is(0));
assertThat(actualSpan.getSpanType(), is(SpanType.Entry));
SpanObject exitSpanObject = traceSegmentObject.getSpans(0);
assertThat(exitSpanObject.getComponentId(), is(2));
assertThat(exitSpanObject.getComponent(), is(""));
assertThat(exitSpanObject.getSpanType(), is(SpanType.Exit));
assertThat(exitSpanObject.getOperationName(), is("/textExitSpan"));
assertThat(exitSpanObject.getParentSpanId(), is(0));
assertThat(exitSpanObject.getSpanId(), is(1));
assertThat(exitSpanObject.getLogsCount(), is(1));
LogMessage logMessage = exitSpanObject.getLogs(0);
assertThat(logMessage.getDataCount(), is(4));
List<KeyWithStringValue> values = logMessage.getDataList();
assertThat(values.get(0).getValue(), is("error"));
assertThat(values.get(1).getValue(), is(RuntimeException.class.getName()));
assertThat(values.get(2).getValue(), is("exception"));
assertTrue(values.get(2).getValue().length() <= 4000);
}
Aggregations