Search in sources :

Example 96 with Span

use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.

the class DependencyLinker method firstRemoteAncestor.

Span firstRemoteAncestor(SpanNode current) {
    SpanNode ancestor = current.parent();
    while (ancestor != null) {
        Span maybeRemote = ancestor.span();
        if (maybeRemote != null && maybeRemote.kind() != null) {
            if (logger.isLoggable(FINE))
                logger.fine("found remote ancestor " + maybeRemote);
            return maybeRemote;
        }
        ancestor = ancestor.parent();
    }
    return null;
}
Also used : Span(zipkin2.Span)

Example 97 with Span

use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.

the class Proto3Codec method read.

public static boolean read(ReadBuffer buffer, Collection<Span> out) {
    if (buffer.available() == 0)
        return false;
    try {
        Span span = SPAN.read(buffer);
        if (span == null)
            return false;
        out.add(span);
        return true;
    } catch (RuntimeException e) {
        throw exceptionReading("Span", e);
    }
}
Also used : Span(zipkin2.Span)

Example 98 with Span

use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.

the class KafkaCollectorWorker method run.

@Override
public void run() {
    try (KafkaConsumer<byte[], byte[]> kafkaConsumer = new KafkaConsumer<>(properties)) {
        kafkaConsumer.subscribe(topics, // added for integration tests only, see ITKafkaCollector
        new ConsumerRebalanceListener() {

            @Override
            public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
                // technically we should remove only the revoked partitions but for test purposes it
                // does not matter
                assignedPartitions.set(Collections.emptyList());
            }

            @Override
            public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
                assignedPartitions.set(Collections.unmodifiableList(new ArrayList<>(partitions)));
            }
        });
        LOG.debug("Kafka consumer starting polling loop.");
        while (running.get()) {
            final ConsumerRecords<byte[], byte[]> consumerRecords = kafkaConsumer.poll(Duration.of(1000, ChronoUnit.MILLIS));
            LOG.debug("Kafka polling returned batch of {} messages.", consumerRecords.count());
            for (ConsumerRecord<byte[], byte[]> record : consumerRecords) {
                final byte[] bytes = record.value();
                metrics.incrementMessages();
                metrics.incrementBytes(bytes.length);
                // lenient on empty messages
                if (bytes.length == 0)
                    continue;
                if (bytes.length < 2) {
                    // need two bytes to check if protobuf
                    metrics.incrementMessagesDropped();
                } else {
                    // If we received legacy single-span encoding, decode it into a singleton list
                    if (!protobuf3(bytes) && bytes[0] <= 16 && bytes[0] != 12) /* thrift, but not list */
                    {
                        Span span;
                        try {
                            span = SpanBytesDecoder.THRIFT.decodeOne(bytes);
                        } catch (RuntimeException e) {
                            metrics.incrementMessagesDropped();
                            continue;
                        }
                        collector.accept(Collections.singletonList(span), NOOP);
                    } else {
                        collector.acceptSpans(bytes, NOOP);
                    }
                }
            }
        }
    } catch (RuntimeException | Error e) {
        LOG.warn("Unexpected error in polling loop spans", e);
        throw e;
    } finally {
        LOG.debug("Kafka consumer polling loop stopped. Kafka consumer closed.");
    }
}
Also used : KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) ConsumerRebalanceListener(org.apache.kafka.clients.consumer.ConsumerRebalanceListener) Span(zipkin2.Span) TopicPartition(org.apache.kafka.common.TopicPartition)

Example 99 with Span

use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.

the class ProtobufSpanDecoder method decodeOne.

public static Span decodeOne(CodedInputStream input) throws IOException {
    Span.Builder span = Span.newBuilder();
    boolean done = false;
    while (!done) {
        int tag = input.readTag();
        switch(tag) {
            case 0:
                done = true;
                break;
            case 10:
                {
                    span.traceId(readHexString(input));
                    break;
                }
            case 18:
                {
                    span.parentId(readHexString(input));
                    break;
                }
            case 26:
                {
                    span.id(readHexString(input));
                    break;
                }
            case 32:
                {
                    int kind = input.readEnum();
                    if (kind == 0)
                        break;
                    if (kind > Span.Kind.values().length)
                        break;
                    span.kind(Span.Kind.values()[kind - 1]);
                    break;
                }
            case 42:
                {
                    span.name(input.readStringRequireUtf8());
                    break;
                }
            case 49:
                {
                    span.timestamp(input.readFixed64());
                    break;
                }
            case 56:
                {
                    span.duration(input.readUInt64());
                    break;
                }
            case 66:
                {
                    int length = input.readRawVarint32();
                    int oldLimit = input.pushLimit(length);
                    span.localEndpoint(decodeEndpoint(input));
                    input.checkLastTagWas(0);
                    input.popLimit(oldLimit);
                    break;
                }
            case 74:
                {
                    int length = input.readRawVarint32();
                    int oldLimit = input.pushLimit(length);
                    span.remoteEndpoint(decodeEndpoint(input));
                    input.checkLastTagWas(0);
                    input.popLimit(oldLimit);
                    break;
                }
            case 82:
                {
                    int length = input.readRawVarint32();
                    int oldLimit = input.pushLimit(length);
                    decodeAnnotation(input, span);
                    input.checkLastTagWas(0);
                    input.popLimit(oldLimit);
                    break;
                }
            case 90:
                {
                    int length = input.readRawVarint32();
                    int oldLimit = input.pushLimit(length);
                    decodeTag(input, span);
                    input.checkLastTagWas(0);
                    input.popLimit(oldLimit);
                    break;
                }
            case 96:
                {
                    span.debug(input.readBool());
                    break;
                }
            case 104:
                {
                    span.shared(input.readBool());
                    break;
                }
            default:
                {
                    logAndSkip(input, tag);
                    break;
                }
        }
    }
    return span.build();
}
Also used : Span(zipkin2.Span) Endpoint(zipkin2.Endpoint)

Example 100 with Span

use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.

the class ProtobufSpanDecoder method decodeList.

public static List<Span> decodeList(CodedInputStream input) {
    ArrayList<Span> spans = new ArrayList<>();
    try {
        boolean done = false;
        while (!done) {
            int tag = input.readTag();
            switch(tag) {
                case 0:
                    done = true;
                    break;
                case 10:
                    int length = input.readRawVarint32();
                    int oldLimit = input.pushLimit(length);
                    spans.add(decodeOne(input));
                    input.checkLastTagWas(0);
                    input.popLimit(oldLimit);
                    break;
                default:
                    {
                        logAndSkip(input, tag);
                        break;
                    }
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return spans;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Span(zipkin2.Span) Endpoint(zipkin2.Endpoint)

Aggregations

Span (zipkin2.Span)326 Test (org.junit.Test)236 Test (org.junit.jupiter.api.Test)78 Endpoint (zipkin2.Endpoint)43 ArrayList (java.util.ArrayList)41 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)41 Span (io.opentelemetry.proto.trace.v1.Span)35 List (java.util.List)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 V1Span (zipkin2.v1.V1Span)17 Span (com.google.devtools.cloudtrace.v2.Span)16 Map (java.util.Map)14 AggregateCall (zipkin2.internal.AggregateCall)13 ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)11 Arrays.asList (java.util.Arrays.asList)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 Annotation (wavefront.report.Annotation)11 Trace (com.google.devtools.cloudtrace.v1.Trace)10 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)10 AttributeValue (com.google.devtools.cloudtrace.v2.AttributeValue)10