@Override public Builder metrics(CollectorMetrics metrics) { if (metrics == null) throw new NullPointerException("metrics == null"); this.metrics = metrics.forTransport("scribe"); delegate.metrics(this.metrics); return this; }
@Override public void incrementMessages() { delegate.incrementMessages(); }
@Override public void incrementSpansDropped(int i) { delegate.incrementMessagesDropped(); }
@Override public ListenableFuture<ResultCode> log(List<LogEntry> messages) { metrics.incrementMessages(); List<Span> spans; try { .map(m -> m.message.getBytes(StandardCharsets.ISO_8859_1)) .peek(b -> metrics.incrementBytes(b.length)) .map(SpanBytesDecoder.THRIFT::decodeOne) .collect(Collectors.toList()); } catch (RuntimeException e) { metrics.incrementMessagesDropped(); return Futures.immediateFailedFuture(e);
MockResponse acceptSpans(RecordedRequest request, SpanBytesDecoder decoder) { metrics.incrementMessages(); byte[] body = request.getBody().readByteArray(); String encoding = request.getHeader("Content-Encoding"); body = result.readByteArray(); } catch (IOException e) { metrics.incrementMessagesDropped(); return new MockResponse().setResponseCode(400).setBody("Cannot gunzip spans");
@Override public void incrementSpanBytes(int i) { delegate.incrementBytes(i); }
@Override public void incrementSpans(int i) { delegate.incrementSpans(i); }
List<Span> sample(List<Span> input) { List<Span> sampled = new ArrayList<>(input.size()); for (int i = 0, length = input.size(); i < length; i++) { Span s = input.get(i); if (sampler.isSampled(s.traceId(), Boolean.TRUE.equals(s.debug()))) { sampled.add(s); } } int dropped = input.size() - sampled.size(); if (dropped > 0) metrics.incrementSpansDropped(dropped); return sampled; }
LOG.debug("Kafka polling returned batch of {} messages.", consumerRecords.count()); for (ConsumerRecord<byte[], byte[]> record : consumerRecords) { metrics.incrementMessages(); final byte[] bytes = record.value(); metrics.incrementMessagesDropped(); } else { metrics.incrementBytes(bytes.length); try { Span span = SpanBytesDecoder.THRIFT.decodeOne(bytes); collector.accept(Collections.singletonList(span), NOOP); } catch (RuntimeException e) { metrics.incrementMessagesDropped();
public void acceptSpans( byte[] serializedSpans, BytesDecoder<Span> decoder, Callback<Void> callback) { metrics.incrementBytes(serializedSpans.length); List<Span> spans; try { spans = decodeList(decoder, serializedSpans); } catch (RuntimeException e) { callback.onError(errorReading(e)); return; } accept(spans, callback); }
public void accept(List<Span> spans, Callback<Void> callback) { if (spans.isEmpty()) { callback.onSuccess(null); return; } metrics.incrementSpans(spans.size()); List<Span> sampled = sample(spans); if (sampled.isEmpty()) { callback.onSuccess(null); return; } try { record(sampled, acceptSpansCallback(sampled)); callback.onSuccess(null); } catch (RuntimeException e) { callback.onError(errorStoringSpans(sampled, e)); return; } }
/** * When storing spans, an exception can be raised before or after the fact. This adds context of * span ids to give logs more relevance. */ RuntimeException errorStoringSpans(List<Span> spans, Throwable e) { metrics.incrementSpansDropped(spans.size()); // The exception could be related to a span being huge. Instead of filling logs, // print trace id, span id pairs StringBuilder msg = appendSpanIds(spans, new StringBuilder("Cannot store spans ")); return doError(msg.toString(), e); }
@Override public void run() { ConsumerIterator<byte[], byte[]> messages = stream.iterator(); while (messages.hasNext()) { byte[] bytes = messages.next().message(); metrics.incrementMessages(); if (bytes.length < 2) { // need two bytes to check if protobuf metrics.incrementMessagesDropped(); continue; } // 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 a list */) { try { metrics.incrementBytes(bytes.length); Span span = SpanBytesDecoder.THRIFT.decodeOne(bytes); collector.accept(Collections.singletonList(span), NOOP); } catch (RuntimeException e) { metrics.incrementMessagesDropped(); } } else { collector.acceptSpans(bytes, NOOP); } } }
@Override public Builder metrics(CollectorMetrics metrics) { if (metrics == null) throw new NullPointerException("metrics == null"); this.metrics = metrics.forTransport("kafka"); delegate.metrics(this.metrics); return this; }
@Override public void incrementMessagesDropped(Throwable throwable) { delegate.incrementMessagesDropped(); }
@Override public void handleDelivery( String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) { metrics.incrementMessages(); this.collector.acceptSpans(body, NOOP); } }
public void acceptSpans(byte[] serialized, Callback<Void> callback) { BytesDecoder<Span> decoder; try { decoder = SpanBytesDecoderDetector.decoderForListMessage(serialized); } catch (RuntimeException e) { metrics.incrementBytes(serialized.length); callback.onError(errorReading(e)); return; } acceptSpans(serialized, decoder, callback); }
@Override public Builder metrics(CollectorMetrics metrics) { if (metrics == null) throw new NullPointerException("metrics == null"); delegate.metrics(metrics.forTransport("kinesis")); return this; }
@Override public void error(HttpServerExchange exchange, IOException e) { ZipkinHttpCollector.this.metrics.incrementMessagesDropped(); ZipkinHttpCollector.error(exchange, e); } };
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { boolean v2 = exchange.getRelativePath().equals("/api/v2/spans"); boolean v1 = !v2 && exchange.getRelativePath().equals("/api/v1/spans"); if (!v2 && !v1) { next.handleRequest(exchange); return; } if (!POST.equals(exchange.getRequestMethod())) { next.handleRequest(exchange); return; } String contentTypeValue = exchange.getRequestHeaders().getFirst(CONTENT_TYPE); boolean json = contentTypeValue == null || contentTypeValue.startsWith("application/json"); boolean thrift = !json && contentTypeValue.startsWith("application/x-thrift"); boolean proto = v2 && !json && contentTypeValue.startsWith("application/x-protobuf"); if (!json && !thrift && !proto) { exchange .setStatusCode(400) .getResponseSender() .send("unsupported content type " + contentTypeValue + "\n"); return; } HttpCollector collector = v2 ? (json ? JSON_V2 : PROTO3) : thrift ? THRIFT : JSON_V1; metrics.incrementMessages(); exchange.getRequestReceiver().receiveFullBytes(collector, errorCallback); }