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;
}
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);
}
}
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.");
}
}
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();
}
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;
}
Aggregations