Search in sources :

Example 1 with SenderException

use of com.uber.jaeger.exceptions.SenderException in project jaeger-client-java by jaegertracing.

the class ThriftSender method flush.

@Override
public int flush() throws SenderException {
    if (spanBuffer.isEmpty()) {
        return 0;
    }
    int n = spanBuffer.size();
    try {
        send(process, spanBuffer);
    } catch (TException e) {
        throw new SenderException("Failed to flush spans.", e, n);
    } finally {
        spanBuffer.clear();
        byteBufferSize = processBytesSize;
    }
    return n;
}
Also used : TException(org.apache.thrift.TException) SenderException(com.uber.jaeger.exceptions.SenderException)

Example 2 with SenderException

use of com.uber.jaeger.exceptions.SenderException in project jaeger-client-java by jaegertracing.

the class ThriftSender method append.

@Override
public int append(Span span) throws SenderException {
    if (process == null) {
        process = new Process(span.getTracer().getServiceName());
        process.setTags(JaegerThriftSpanConverter.buildTags(span.getTracer().tags()));
        processBytesSize = getSizeOfSerializedThrift(process);
        byteBufferSize += processBytesSize;
    }
    com.uber.jaeger.thriftjava.Span thriftSpan = JaegerThriftSpanConverter.convertSpan(span);
    int spanSize = getSizeOfSerializedThrift(thriftSpan);
    if (spanSize > maxSpanBytes) {
        throw new SenderException(String.format("ThriftSender received a span that was too large, size = %d, max = %d", spanSize, maxSpanBytes), null, 1);
    }
    byteBufferSize += spanSize;
    if (byteBufferSize <= maxSpanBytes) {
        spanBuffer.add(thriftSpan);
        if (byteBufferSize < maxSpanBytes) {
            return 0;
        }
        return flush();
    }
    int n;
    try {
        n = flush();
    } catch (SenderException e) {
        // +1 for the span not submitted in the buffer above
        throw new SenderException(e.getMessage(), e.getCause(), e.getDroppedSpanCount() + 1);
    }
    spanBuffer.add(thriftSpan);
    byteBufferSize = processBytesSize + spanSize;
    return n;
}
Also used : Process(com.uber.jaeger.thriftjava.Process) SenderException(com.uber.jaeger.exceptions.SenderException)

Example 3 with SenderException

use of com.uber.jaeger.exceptions.SenderException in project jaeger-client-java by jaegertracing.

the class ZipkinSender method append.

/*
   * Adds spans to an internal queue that flushes them as udp packets later.
   * This function does not need to be synchronized because the reporter creates
   * a single thread that calls this append function
   */
@Override
public int append(com.uber.jaeger.Span span) throws SenderException {
    byte[] next = encoder.encode(backFillHostOnAnnotations(ThriftSpanConverter.convertSpan(span)));
    int messageSizeOfNextSpan = delegate.messageSizeInBytes(Collections.singletonList(next));
    // don't enqueue something larger than we can drain
    if (messageSizeOfNextSpan > delegate.messageMaxBytes()) {
        throw new SenderException(delegate.toString() + " received a span that was too large", null, 1);
    }
    // speculatively add to the buffer so we can size it
    spanBuffer.add(next);
    int nextSizeInBytes = delegate.messageSizeInBytes(spanBuffer);
    // If we can fit queued spans and the next into one message...
    if (nextSizeInBytes <= delegate.messageMaxBytes()) {
        // If there's still room, don't flush yet.
        if (nextSizeInBytes < delegate.messageMaxBytes()) {
            return 0;
        }
        // If we have exactly met the max message size, flush
        return flush();
    }
    // Otherwise, remove speculatively added span and flush until we have room for it.
    spanBuffer.remove(spanBuffer.size() - 1);
    int n;
    try {
        n = flush();
    } catch (SenderException e) {
        // +1 for the span not submitted in the buffer above
        throw new SenderException(e.getMessage(), e.getCause(), e.getDroppedSpanCount() + 1);
    }
    // Now that there's room, add the span as the only element in the buffer
    spanBuffer.add(next);
    return n;
}
Also used : SenderException(com.uber.jaeger.exceptions.SenderException) Endpoint(com.twitter.zipkin.thriftjava.Endpoint)

Example 4 with SenderException

use of com.uber.jaeger.exceptions.SenderException in project jaeger-client-java by jaegertracing.

the class ZipkinSender method flush.

@Override
public int flush() throws SenderException {
    if (spanBuffer.isEmpty()) {
        return 0;
    }
    AwaitableCallback captor = new AwaitableCallback();
    int n = spanBuffer.size();
    try {
        delegate.sendSpans(spanBuffer, captor);
        captor.await();
    } catch (RuntimeException e) {
        throw new SenderException("Failed to flush spans.", e, n);
    } finally {
        spanBuffer.clear();
    }
    return n;
}
Also used : AwaitableCallback(zipkin.reporter.internal.AwaitableCallback) SenderException(com.uber.jaeger.exceptions.SenderException) Endpoint(com.twitter.zipkin.thriftjava.Endpoint)

Example 5 with SenderException

use of com.uber.jaeger.exceptions.SenderException in project jaeger-client-java by jaegertracing.

the class ZipkinSenderTest method testAppendSpanTooLarge.

@Test
public void testAppendSpanTooLarge() throws Exception {
    Span jaegerSpan = (Span) tracer.buildSpan("raza").startManual();
    String msg = "";
    for (int i = 0; i < 1001; i++) {
        msg += ".";
    }
    jaegerSpan.log(msg);
    try {
        sender.append(jaegerSpan);
        fail("The line above shoud throw");
    } catch (SenderException e) {
        assertEquals(e.getDroppedSpanCount(), 1);
    }
}
Also used : SenderException(com.uber.jaeger.exceptions.SenderException) Span(com.uber.jaeger.Span) Test(org.junit.Test)

Aggregations

SenderException (com.uber.jaeger.exceptions.SenderException)6 Endpoint (com.twitter.zipkin.thriftjava.Endpoint)2 Span (com.uber.jaeger.Span)2 Test (org.junit.Test)2 Process (com.uber.jaeger.thriftjava.Process)1 TException (org.apache.thrift.TException)1 AwaitableCallback (zipkin.reporter.internal.AwaitableCallback)1