Search in sources :

Example 1 with ResultCode

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());
}
Also used : ArrayList(java.util.ArrayList) Span(zipkin2.Span) LogEntry(zipkin2.collector.scribe.generated.LogEntry)

Example 2 with ResultCode

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();
}
Also used : Scribe(zipkin2.collector.scribe.generated.Scribe) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.layered.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) LogEntry(zipkin2.collector.scribe.generated.LogEntry) ResultCode(zipkin2.collector.scribe.generated.ResultCode) TSocket(org.apache.thrift.transport.TSocket) Test(org.junit.jupiter.api.Test)

Aggregations

LogEntry (zipkin2.collector.scribe.generated.LogEntry)2 ArrayList (java.util.ArrayList)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TSocket (org.apache.thrift.transport.TSocket)1 TTransport (org.apache.thrift.transport.TTransport)1 TFramedTransport (org.apache.thrift.transport.layered.TFramedTransport)1 Test (org.junit.jupiter.api.Test)1 Span (zipkin2.Span)1 ResultCode (zipkin2.collector.scribe.generated.ResultCode)1 Scribe (zipkin2.collector.scribe.generated.Scribe)1