use of org.apache.skywalking.apm.network.proto.UniqueId 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.UniqueId in project incubator-skywalking by apache.
the class TraceStackService method buildSpanList.
private List<Span> buildSpanList(String traceId, String segmentId, int applicationId, List<SpanObject> spanObjects) {
List<Span> spans = new ArrayList<>();
spanObjects.forEach(spanObject -> {
Span span = new Span();
span.setTraceId(traceId);
span.setSegmentId(segmentId);
span.setSpanId(spanObject.getSpanId());
span.setParentSpanId(spanObject.getParentSpanId());
span.setStartTime(spanObject.getStartTime());
span.setEndTime(spanObject.getEndTime());
span.setError(spanObject.getIsError());
span.setLayer(spanObject.getSpanLayer().name());
span.setType(spanObject.getSpanType().name());
String segmentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(spanObject.getSpanId());
span.setSegmentSpanId(segmentSpanId);
String segmentParentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(spanObject.getParentSpanId());
span.setSegmentParentSpanId(segmentParentSpanId);
if (spanObject.getPeerId() == 0) {
span.setPeer(spanObject.getPeer());
} else {
span.setPeer(networkAddressCacheService.getAddress(spanObject.getPeerId()));
}
String operationName = spanObject.getOperationName();
if (spanObject.getOperationNameId() != 0) {
ServiceName serviceName = serviceNameCacheService.get(spanObject.getOperationNameId());
if (ObjectUtils.isNotEmpty(serviceName)) {
operationName = serviceName.getServiceName();
} else {
operationName = Const.EMPTY_STRING;
}
}
span.setOperationName(operationName);
String applicationCode = applicationCacheService.getApplicationById(applicationId).getApplicationCode();
span.setApplicationCode(applicationCode);
if (spanObject.getComponentId() == 0) {
span.setComponent(spanObject.getComponent());
} else {
span.setComponent(ComponentsDefine.getInstance().getComponentName(spanObject.getComponentId()));
}
spanObject.getRefsList().forEach(reference -> {
Ref ref = new Ref();
ref.setTraceId(traceId);
switch(reference.getRefType()) {
case CrossThread:
ref.setType(RefType.CROSS_THREAD);
break;
case CrossProcess:
ref.setType(RefType.CROSS_PROCESS);
break;
}
ref.setParentSpanId(reference.getParentSpanId());
UniqueId uniqueId = reference.getParentTraceSegmentId();
StringBuilder segmentIdBuilder = new StringBuilder();
for (int i = 0; i < uniqueId.getIdPartsList().size(); i++) {
if (i == 0) {
segmentIdBuilder.append(String.valueOf(uniqueId.getIdPartsList().get(i)));
} else {
segmentIdBuilder.append(".").append(String.valueOf(uniqueId.getIdPartsList().get(i)));
}
}
ref.setParentSegmentId(segmentIdBuilder.toString());
span.setSegmentParentSpanId(ref.getParentSegmentId() + Const.SEGMENT_SPAN_SPLIT + String.valueOf(ref.getParentSpanId()));
span.getRefs().add(ref);
});
spanObject.getTagsList().forEach(tag -> {
KeyValue keyValue = new KeyValue();
keyValue.setKey(tag.getKey());
keyValue.setValue(tag.getValue());
span.getTags().add(keyValue);
});
spanObject.getLogsList().forEach(log -> {
LogEntity logEntity = new LogEntity();
logEntity.setTime(log.getTime());
log.getDataList().forEach(data -> {
KeyValue keyValue = new KeyValue();
keyValue.setKey(data.getKey());
keyValue.setValue(data.getValue());
logEntity.getData().add(keyValue);
});
span.getLogs().add(logEntity);
});
spans.add(span);
});
return spans;
}
use of org.apache.skywalking.apm.network.proto.UniqueId in project incubator-skywalking by apache.
the class SegmentParse method parse.
@GraphComputingMetric(name = "/segment/parse")
public boolean parse(UpstreamSegment segment, ISegmentParseService.Source source) {
createSpanListeners();
try {
List<UniqueId> traceIds = segment.getGlobalTraceIdsList();
TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(segment.getSegment());
SegmentDecorator segmentDecorator = new SegmentDecorator(segmentObject);
if (!preBuild(traceIds, segmentDecorator)) {
logger.debug("This segment id exchange not success, write to buffer file, id: {}", segmentId);
if (source.equals(ISegmentParseService.Source.Agent)) {
writeToBufferFile(segmentId, segment);
}
return false;
} else {
logger.debug("This segment id exchange success, id: {}", segmentId);
notifyListenerToBuild();
buildSegment(segmentId, segmentDecorator.toByteArray());
return true;
}
} catch (InvalidProtocolBufferException e) {
logger.error(e.getMessage(), e);
}
return false;
}
use of org.apache.skywalking.apm.network.proto.UniqueId in project incubator-skywalking by apache.
the class SegmentParse method preBuild.
@GraphComputingMetric(name = "/segment/parse/preBuild")
private boolean preBuild(List<UniqueId> traceIds, SegmentDecorator segmentDecorator) {
StringBuilder segmentIdBuilder = new StringBuilder();
for (int i = 0; i < segmentDecorator.getTraceSegmentId().getIdPartsList().size(); i++) {
if (i == 0) {
segmentIdBuilder.append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i));
} else {
segmentIdBuilder.append(".").append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i));
}
}
segmentId = segmentIdBuilder.toString();
for (UniqueId uniqueId : traceIds) {
notifyGlobalsListener(uniqueId);
}
int applicationId = segmentDecorator.getApplicationId();
int applicationInstanceId = segmentDecorator.getApplicationInstanceId();
int entrySpanCount = 0;
for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
if (!SpanIdExchanger.getInstance(moduleManager).exchange(spanDecorator, applicationId)) {
return false;
} else {
for (int j = 0; j < spanDecorator.getRefsCount(); j++) {
ReferenceDecorator referenceDecorator = spanDecorator.getRefs(j);
if (!ReferenceIdExchanger.getInstance(moduleManager).exchange(referenceDecorator, applicationId)) {
return false;
}
}
}
if (SpanType.Entry.equals(spanDecorator.getSpanType())) {
entrySpanCount++;
}
if (entrySpanCount > 1) {
throw new UnexpectedException("This segment contains multiple entry span.");
}
}
for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
if (spanDecorator.getSpanId() == 0) {
notifyFirstListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
}
if (SpanType.Exit.equals(spanDecorator.getSpanType())) {
notifyExitListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
} else if (SpanType.Entry.equals(spanDecorator.getSpanType())) {
notifyEntryListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
} else if (SpanType.Local.equals(spanDecorator.getSpanType())) {
notifyLocalListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
} else {
logger.error("span type value was unexpected, span type name: {}", spanDecorator.getSpanType().name());
}
}
return true;
}
Aggregations