Search in sources :

Example 1 with Ref

use of org.apache.skywalking.apm.collector.storage.ui.trace.Ref 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;
}
Also used : UniqueId(org.apache.skywalking.apm.network.proto.UniqueId) Ref(org.apache.skywalking.apm.collector.storage.ui.trace.Ref) KeyValue(org.apache.skywalking.apm.collector.storage.ui.trace.KeyValue) ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) ArrayList(java.util.ArrayList) Span(org.apache.skywalking.apm.collector.storage.ui.trace.Span) LogEntity(org.apache.skywalking.apm.collector.storage.ui.trace.LogEntity)

Aggregations

ArrayList (java.util.ArrayList)1 ServiceName (org.apache.skywalking.apm.collector.storage.table.register.ServiceName)1 KeyValue (org.apache.skywalking.apm.collector.storage.ui.trace.KeyValue)1 LogEntity (org.apache.skywalking.apm.collector.storage.ui.trace.LogEntity)1 Ref (org.apache.skywalking.apm.collector.storage.ui.trace.Ref)1 Span (org.apache.skywalking.apm.collector.storage.ui.trace.Span)1 UniqueId (org.apache.skywalking.apm.network.proto.UniqueId)1