@Override public void onError(Throwable t) { metrics.incrementMessagesDropped(t); metrics.incrementSpansDropped(count); if (logger.isLoggable(FINE)) { logger.log(FINE, format("Dropped %s spans due to %s(%s)", count, t.getClass().getSimpleName(), t.getMessage() == null ? "" : t.getMessage()), t); } } };
/** Returns true if the was encoded and accepted onto the queue. */ @Override public void report(S span) { if (span == null) throw new NullPointerException("span == null"); metrics.incrementSpans(1); byte[] next = encoder.encode(span); int messageSizeOfNextSpan = sender.messageSizeInBytes(Collections.singletonList(next)); metrics.incrementSpanBytes(next.length); if (closed.get() || // don't enqueue something larger than we can drain messageSizeOfNextSpan > messageMaxBytes || !pending.offer(next)) { metrics.incrementSpansDropped(1); } }
void flush(BufferNextMessage bundler) { if (closed.get()) throw new IllegalStateException("closed"); pending.drainTo(bundler, bundler.remainingNanos()); // record after flushing reduces the amount of gauge events vs on doing this on report metrics.updateQueuedSpans(pending.count); metrics.updateQueuedBytes(pending.sizeInBytes); // loop around if we are running, and the bundle isn't full // if we are closed, try to send what's pending if (!bundler.isReady() && !closed.get()) return; // Signal that we are about to send a message of a known size in bytes metrics.incrementMessages(); metrics.incrementMessageBytes(bundler.sizeInBytes()); List<byte[]> nextMessage = bundler.drain(); // In failure case, we increment messages and spans dropped. Callback failureCallback = sendSpansCallback(nextMessage.size()); try { sender.sendSpans(nextMessage, failureCallback); } catch (RuntimeException e) { failureCallback.onError(e); // Raise in case the sender was closed out-of-band. if (e instanceof IllegalStateException) throw e; } }
@Override public void close() { if (!closed.compareAndSet(false, true)) return; // already closed try { // wait for in-flight spans to send if (!close.await(closeTimeoutNanos, TimeUnit.NANOSECONDS)) { logger.warning("Timed out waiting for in-flight spans to send"); } } catch (InterruptedException e) { logger.warning("Interrupted waiting for in-flight spans to send"); Thread.currentThread().interrupt(); } int count = pending.clear(); if (count > 0) { metrics.incrementSpansDropped(count); logger.warning("Dropped " + count + " spans due to AsyncReporter.close()"); } }