use of zipkin2.collector.scribe.generated.ResultCode in project zipkin by openzipkin.
the class ScribeSpanConsumer method Log.
@Override
public void Log(List<LogEntry> messages, AsyncMethodCallback<ResultCode> resultHandler) {
metrics.incrementMessages();
List<Span> spans = new ArrayList<>();
int byteCount = 0;
try {
for (LogEntry logEntry : messages) {
if (!category.equals(logEntry.category))
continue;
byte[] bytes = logEntry.message.getBytes(StandardCharsets.ISO_8859_1);
// finagle-zipkin uses mime encoding
bytes = Base64.getMimeDecoder().decode(bytes);
byteCount += bytes.length;
spans.add(SpanBytesDecoder.THRIFT.decodeOne(bytes));
}
} catch (RuntimeException e) {
metrics.incrementMessagesDropped();
resultHandler.onError(e);
return;
} finally {
metrics.incrementBytes(byteCount);
}
collector.accept(spans, new Callback<Void>() {
@Override
public void onSuccess(Void value) {
resultHandler.onComplete(ResultCode.OK);
}
@Override
public void onError(Throwable t) {
Exception error = t instanceof Exception ? (Exception) t : new RuntimeException(t);
resultHandler.onError(error);
}
}, CommonPools.blockingTaskExecutor());
}
use of zipkin2.collector.scribe.generated.ResultCode in project zipkin by openzipkin.
the class ITScribeCollector method normal.
@Test
void normal() throws Exception {
// Java version of this sample code
// https://github.com/facebookarchive/scribe/wiki/Logging-Messages
TTransport transport = new TFramedTransport(new TSocket("localhost", server.port()));
TProtocol protocol = new TBinaryProtocol(transport, false, false);
Scribe.Iface client = new Scribe.Client(protocol);
List<LogEntry> entries = TestObjects.TRACE.stream().map(ITScribeCollector::logEntry).collect(Collectors.toList());
transport.open();
try {
ResultCode code = client.Log(entries);
assertThat(code).isEqualTo(ResultCode.OK);
code = client.Log(entries);
assertThat(code).isEqualTo(ResultCode.OK);
} finally {
transport.close();
}
verify(collector, times(2)).accept(eq(TestObjects.TRACE), any(), eq(CommonPools.blockingTaskExecutor()));
verify(metrics, times(2)).incrementMessages();
}
Aggregations