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"));
}
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;
}
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());
}
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;
}
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;
}
Aggregations