Search in sources :

Example 1 with SpanDecorator

use of org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SpanDecorator 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;
}
Also used : UniqueId(org.apache.skywalking.apm.network.proto.UniqueId) UnexpectedException(org.apache.skywalking.apm.collector.core.UnexpectedException) SpanDecorator(org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SpanDecorator) ReferenceDecorator(org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator) GraphComputingMetric(org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)

Aggregations

ReferenceDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator)1 SpanDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SpanDecorator)1 UnexpectedException (org.apache.skywalking.apm.collector.core.UnexpectedException)1 GraphComputingMetric (org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)1 UniqueId (org.apache.skywalking.apm.network.proto.UniqueId)1