Search in sources :

Example 1 with SenderException

use of io.jaegertracing.internal.exceptions.SenderException in project jaeger-client-java by jaegertracing.

the class RemoteReporterTest method testUpdateErrorMetricWhenCommandExecuteFails.

@Test
public void testUpdateErrorMetricWhenCommandExecuteFails() throws Exception {
    int reporterFailures = 5;
    sender = new InMemorySender() {

        @Override
        public int append(JaegerSpan span) throws SenderException {
            throw new SenderException("", reporterFailures);
        }
    };
    RemoteReporter reporter = new Builder().withSender(sender).withFlushInterval(flushInterval).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
    reporter.report(newSpan());
    reporter.close();
    assertEquals(reporterFailures, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=err"));
}
Also used : Builder(io.jaegertracing.internal.reporters.RemoteReporter.Builder) JaegerSpan(io.jaegertracing.internal.JaegerSpan) InMemorySender(io.jaegertracing.internal.senders.InMemorySender) SenderException(io.jaegertracing.internal.exceptions.SenderException) Test(org.junit.Test)

Example 2 with SenderException

use of io.jaegertracing.internal.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(JaegerSpan 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(io.jaegertracing.internal.exceptions.SenderException) Endpoint(com.twitter.zipkin.thriftjava.Endpoint)

Example 3 with SenderException

use of io.jaegertracing.internal.exceptions.SenderException in project jaeger-client-java by jaegertracing.

the class HttpSender method send.

@Override
public void send(Process process, List<Span> spans) throws SenderException {
    Batch batch = new Batch(process, spans);
    byte[] bytes = null;
    try {
        bytes = serialize(batch);
    } catch (Exception e) {
        throw new SenderException(String.format("Failed to serialize %d spans", spans.size()), e, spans.size());
    }
    RequestBody body = RequestBody.create(MEDIA_TYPE_THRIFT, bytes);
    Request request = requestBuilder.post(body).build();
    Response response;
    try {
        response = httpClient.newCall(request).execute();
    } catch (IOException e) {
        throw new SenderException(String.format("Could not send %d spans", spans.size()), e, spans.size());
    }
    if (response.isSuccessful()) {
        response.close();
        return;
    }
    String responseBody;
    try {
        responseBody = response.body() != null ? response.body().string() : "null";
    } catch (IOException e) {
        responseBody = "unable to read response";
    }
    String exceptionMessage = String.format("Could not send %d spans, response %d: %s", spans.size(), response.code(), responseBody);
    throw new SenderException(exceptionMessage, null, spans.size());
}
Also used : Response(okhttp3.Response) Batch(io.jaegertracing.thriftjava.Batch) Request(okhttp3.Request) IOException(java.io.IOException) ToString(lombok.ToString) SenderException(io.jaegertracing.internal.exceptions.SenderException) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) SenderException(io.jaegertracing.internal.exceptions.SenderException) RequestBody(okhttp3.RequestBody)

Example 4 with SenderException

use of io.jaegertracing.internal.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 (SenderException e) {
        throw new SenderException("Failed to flush spans.", e, n);
    } finally {
        spanBuffer.clear();
        spanBytesSize = 0;
    }
    return n;
}
Also used : SenderException(io.jaegertracing.internal.exceptions.SenderException)

Example 5 with SenderException

use of io.jaegertracing.internal.exceptions.SenderException in project jaeger-client-java by jaegertracing.

the class ThriftSender method append.

@Override
public int append(JaegerSpan span) throws SenderException {
    if (process == null) {
        process = new Process(span.getTracer().getServiceName());
        process.setTags(JaegerThriftSpanConverter.buildTags(span.getTracer().tags()));
        processBytesSize = calculateProcessSize(process);
    }
    io.jaegertracing.thriftjava.Span thriftSpan = JaegerThriftSpanConverter.convertSpan(span);
    int spanSize = calculateSpanSize(thriftSpan);
    if (spanSize > getMaxSpanBytes()) {
        throw new SenderException(String.format("ThriftSender received a span that was too large, size = %d, max = %d", spanSize, getMaxSpanBytes()), null, 1);
    }
    spanBytesSize += spanSize;
    if (spanBytesSize <= getMaxSpanBytes()) {
        spanBuffer.add(thriftSpan);
        if (spanBytesSize < getMaxSpanBytes()) {
            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);
    spanBytesSize = spanSize;
    return n;
}
Also used : Process(io.jaegertracing.thriftjava.Process) SenderException(io.jaegertracing.internal.exceptions.SenderException)

Aggregations

SenderException (io.jaegertracing.internal.exceptions.SenderException)10 Test (org.junit.Test)6 Process (io.jaegertracing.thriftjava.Process)4 JaegerSpan (io.jaegertracing.internal.JaegerSpan)3 JaegerTracer (io.jaegertracing.internal.JaegerTracer)3 Builder (io.jaegertracing.internal.reporters.RemoteReporter.Builder)2 InMemorySender (io.jaegertracing.internal.senders.InMemorySender)2 List (java.util.List)2 Endpoint (com.twitter.zipkin.thriftjava.Endpoint)1 ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)1 Batch (io.jaegertracing.thriftjava.Batch)1 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ToString (lombok.ToString)1 Request (okhttp3.Request)1 RequestBody (okhttp3.RequestBody)1 Response (okhttp3.Response)1 TTransportException (org.apache.thrift.transport.TTransportException)1