use of org.apache.skywalking.apm.network.proto.SpanObject in project incubator-skywalking by apache.
the class SegmentBase64Printer method main.
public static void main(String[] args) throws InvalidProtocolBufferException {
String segmentBase64 = "CgwKCgMXjPKUga3WgBsSvAEIARiF7Jq1nywgp+yatZ8sKlASDAoKAnPAqKD5rNaAGxgBIAIqDjEyNy4wLjAuMTo5MDkyOAJCFC9zZW5kTWVzc2FnZS97Y291bnR9UhQvc2VuZE1lc3NhZ2Uve2NvdW50fTocS2Fma2EvVHJhY2UtdG9waWMtMS9Db25zdW1lclgEYBt6GwoJbXEuYnJva2VyEg4xMjcuMC4wLjE6OTA5MnoZCghtcS50b3BpYxINVHJhY2UtdG9waWMtMRImEP///////////wEY/+uatZ8sILTsmrWfLDD///////////8BUAIYAiAD";
byte[] binarySegment = Base64.getDecoder().decode(segmentBase64);
TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(binarySegment);
UniqueId segmentId = segmentObject.getTraceSegmentId();
StringBuilder segmentIdBuilder = new StringBuilder();
for (int i = 0; i < segmentId.getIdPartsList().size(); i++) {
if (i == 0) {
segmentIdBuilder.append(segmentId.getIdPartsList().get(i));
} else {
segmentIdBuilder.append(".").append(segmentId.getIdPartsList().get(i));
}
}
LOGGER.info("SegmentId: {}", segmentIdBuilder.toString());
LOGGER.info("ApplicationId: {}", segmentObject.getApplicationId());
LOGGER.info("ApplicationInstanceId: {}", segmentObject.getApplicationInstanceId());
List<SpanObject> spansList = segmentObject.getSpansList();
LOGGER.info("Spans:");
spansList.forEach(span -> {
LOGGER.info(" Span:");
LOGGER.info(" SpanId: {}", span.getSpanId());
LOGGER.info(" ParentSpanId: {}", span.getParentSpanId());
LOGGER.info(" SpanLayer: {}", span.getSpanLayer());
LOGGER.info(" SpanType: {}", span.getSpanType());
LOGGER.info(" StartTime: {}", span.getStartTime());
LOGGER.info(" EndTime: {}", span.getEndTime());
LOGGER.info(" ComponentId: {}", span.getComponentId());
LOGGER.info(" Component: {}", span.getComponent());
LOGGER.info(" OperationNameId: {}", span.getOperationNameId());
LOGGER.info(" OperationName: {}", span.getOperationName());
LOGGER.info(" PeerId: {}", span.getPeerId());
LOGGER.info(" Peer: {}", span.getPeer());
LOGGER.info(" IsError: {}", span.getIsError());
LOGGER.info(" reference:");
span.getRefsList().forEach(reference -> {
LOGGER.info(" EntryApplicationInstanceId: {}", reference.getEntryApplicationInstanceId());
LOGGER.info(" EntryServiceId: {}", reference.getEntryServiceId());
LOGGER.info(" EntryServiceName: {}", reference.getEntryServiceName());
LOGGER.info(" ParentTraceSegmentId: {}", reference.getParentTraceSegmentId());
LOGGER.info(" ParentSpanId: {}", reference.getParentSpanId());
LOGGER.info(" ParentApplicationInstanceId: {}", reference.getParentApplicationInstanceId());
LOGGER.info(" ParentServiceId: {}", reference.getParentServiceId());
LOGGER.info(" ParentServiceName: {}", reference.getParentServiceName());
LOGGER.info(" NetworkAddressId: {}", reference.getNetworkAddressId());
LOGGER.info(" NetworkAddress: {}", reference.getNetworkAddress());
});
});
}
use of org.apache.skywalking.apm.network.proto.SpanObject in project incubator-skywalking by apache.
the class TraceSegmentServiceClientTest method testSendTraceSegmentWithoutException.
@Test
public void testSendTraceSegmentWithoutException() throws InvalidProtocolBufferException {
grpcServerRule.getServiceRegistry().addService(serviceImplBase);
AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", null);
firstEntrySpan.setComponent(ComponentsDefine.TOMCAT);
Tags.HTTP.METHOD.set(firstEntrySpan, "GET");
Tags.URL.set(firstEntrySpan, "127.0.0.1:8080");
SpanLayer.asHttp(firstEntrySpan);
ContextManager.stopSpan();
serviceClient.consume(storage.getTraceSegments());
assertThat(upstreamSegments.size(), is(1));
UpstreamSegment upstreamSegment = upstreamSegments.get(0);
assertThat(upstreamSegment.getGlobalTraceIdsCount(), is(1));
TraceSegmentObject traceSegmentObject = TraceSegmentObject.parseFrom(upstreamSegment.getSegment());
assertThat(traceSegmentObject.getSpans(0).getRefsCount(), is(0));
assertThat(traceSegmentObject.getSpansCount(), is(1));
SpanObject spanObject = traceSegmentObject.getSpans(0);
assertThat(spanObject.getSpanType(), is(SpanType.Entry));
assertThat(spanObject.getSpanId(), is(0));
assertThat(spanObject.getParentSpanId(), is(-1));
}
use of org.apache.skywalking.apm.network.proto.SpanObject in project incubator-skywalking by apache.
the class SpanService method load.
public JsonObject load(String segmentId, int spanId) {
TraceSegmentObject segmentObject = segmentDAO.load(segmentId);
JsonObject spanJson = new JsonObject();
List<SpanObject> spans = segmentObject.getSpansList();
for (SpanObject spanObject : spans) {
if (spanId == spanObject.getSpanId()) {
String operationName = spanObject.getOperationName();
if (spanObject.getOperationNameId() != 0) {
ServiceName serviceName = serviceNameCacheService.get(spanObject.getOperationNameId());
if (StringUtils.isNotEmpty(serviceName)) {
operationName = serviceName.getServiceName();
}
}
spanJson.addProperty("operationName", operationName);
spanJson.addProperty("startTime", spanObject.getStartTime());
spanJson.addProperty("endTime", spanObject.getEndTime());
JsonArray logsArray = new JsonArray();
List<LogMessage> logs = spanObject.getLogsList();
for (LogMessage logMessage : logs) {
JsonObject logJson = new JsonObject();
logJson.addProperty("time", logMessage.getTime());
JsonArray logInfoArray = new JsonArray();
for (KeyWithStringValue value : logMessage.getDataList()) {
JsonObject valueJson = new JsonObject();
valueJson.addProperty("key", value.getKey());
valueJson.addProperty("value", value.getValue());
logInfoArray.add(valueJson);
}
logJson.add("logInfo", logInfoArray);
logsArray.add(logJson);
}
spanJson.add("logMessage", logsArray);
JsonArray tagsArray = new JsonArray();
JsonObject spanTypeJson = new JsonObject();
spanTypeJson.addProperty("key", "span type");
spanTypeJson.addProperty("value", spanObject.getSpanType().name());
tagsArray.add(spanTypeJson);
JsonObject componentJson = new JsonObject();
componentJson.addProperty("key", "component");
if (spanObject.getComponentId() == 0) {
componentJson.addProperty("value", spanObject.getComponent());
} else {
componentJson.addProperty("value", ComponentsDefine.getInstance().getComponentName(spanObject.getComponentId()));
}
tagsArray.add(componentJson);
JsonObject peerJson = new JsonObject();
peerJson.addProperty("key", "peer");
if (spanObject.getPeerId() == 0) {
peerJson.addProperty("value", spanObject.getPeer());
} else {
peerJson.addProperty("value", applicationCacheService.getApplicationById(spanObject.getPeerId()).getApplicationCode());
}
tagsArray.add(peerJson);
for (KeyWithStringValue tagValue : spanObject.getTagsList()) {
JsonObject tagJson = new JsonObject();
tagJson.addProperty("key", tagValue.getKey());
tagJson.addProperty("value", tagValue.getValue());
tagsArray.add(tagJson);
}
JsonObject isErrorJson = new JsonObject();
isErrorJson.addProperty("key", "is error");
isErrorJson.addProperty("value", spanObject.getIsError());
tagsArray.add(isErrorJson);
spanJson.add("tags", tagsArray);
}
}
return spanJson;
}
use of org.apache.skywalking.apm.network.proto.SpanObject 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