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; }
/** * 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); }