use of io.jaegertracing.thriftjava.Log in project instrumentation-java by census-instrumentation.
the class JaegerExporterHandler method timedEventsToLogs.
private static List<Log> timedEventsToLogs(final List<SpanData.TimedEvent<Annotation>> annotations, final List<SpanData.TimedEvent<MessageEvent>> messageEvents) {
final List<Log> logs = Lists.newArrayListWithExpectedSize(annotations.size() + messageEvents.size());
for (final SpanData.TimedEvent<Annotation> event : annotations) {
final long timestampsInMicros = timestampToMicros(event.getTimestamp());
logs.add(new Log(timestampsInMicros, attributesToTags(event.getEvent().getAttributes(), descriptionToTag(event.getEvent().getDescription()))));
}
for (final SpanData.TimedEvent<MessageEvent> event : messageEvents) {
final long timestampsInMicros = timestampToMicros(event.getTimestamp());
final Tag tagMessageId = new Tag(MESSAGE_EVENT_ID, TagType.LONG).setVLong(event.getEvent().getMessageId());
final Tag tagCompressedSize = new Tag(MESSAGE_EVENT_COMPRESSED_SIZE, TagType.LONG).setVLong(event.getEvent().getCompressedMessageSize());
final Tag tagUncompressedSize = new Tag(MESSAGE_EVENT_UNCOMPRESSED_SIZE, TagType.LONG).setVLong(event.getEvent().getUncompressedMessageSize());
logs.add(new Log(timestampsInMicros, Arrays.asList(event.getEvent().getType() == Type.RECEIVED ? RECEIVED_MESSAGE_EVENT_TAG : SENT_MESSAGE_EVENT_TAG, tagMessageId, tagCompressedSize, tagUncompressedSize)));
}
return logs;
}
use of io.jaegertracing.thriftjava.Log in project jaeger-client-java by jaegertracing.
the class JaegerThriftSpanConverterTest method testConvertSpan.
@Test
public void testConvertSpan() {
Map<String, Object> fields = new HashMap<String, Object>();
fields.put("k", "v");
JaegerSpan span = tracer.buildSpan("operation-name").start();
span = span.log(1, fields);
span = span.setBaggageItem("foo", "bar");
io.jaegertracing.thriftjava.Span thriftSpan = JaegerThriftSpanConverter.convertSpan(span);
assertEquals("operation-name", thriftSpan.getOperationName());
assertEquals(2, thriftSpan.getLogs().size());
Log thriftLog = thriftSpan.getLogs().get(0);
assertEquals(1, thriftLog.getTimestamp());
assertEquals(1, thriftLog.getFields().size());
Tag thriftTag = thriftLog.getFields().get(0);
assertEquals("k", thriftTag.getKey());
assertEquals("v", thriftTag.getVStr());
thriftLog = thriftSpan.getLogs().get(1);
assertEquals(3, thriftLog.getFields().size());
thriftTag = thriftLog.getFields().get(0);
assertEquals("event", thriftTag.getKey());
assertEquals("baggage", thriftTag.getVStr());
thriftTag = thriftLog.getFields().get(1);
assertEquals("value", thriftTag.getKey());
assertEquals("bar", thriftTag.getVStr());
thriftTag = thriftLog.getFields().get(2);
assertEquals("key", thriftTag.getKey());
assertEquals("foo", thriftTag.getVStr());
}
use of io.jaegertracing.thriftjava.Log in project java by wavefrontHQ.
the class JaegerPortUnificationHandlerTest method testJaegerPortUnificationHandler.
@Test
public void testJaegerPortUnificationHandler() throws Exception {
reset(mockTraceHandler, mockTraceSpanLogsHandler, mockCtx);
Span expectedSpan1 = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(1234).setName("HTTP GET").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("jaegerSpanId", "12d687"), new Annotation("jaegerTraceId", "499602d20000011f71fb04cb"), new Annotation("service", "frontend"), new Annotation("component", "db"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("_spanLogs", "true"))).build();
mockTraceHandler.report(expectedSpan1);
expectLastCall();
mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("default").setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(startTime * 1000).setFields(ImmutableMap.of("event", "error", "exception", "NullPointerException")).build())).build());
expectLastCall();
mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(2345).setName("HTTP GET /").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-0000-00000023cace").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("jaegerSpanId", "23cace"), new Annotation("jaegerTraceId", "499602d20000011f71fb04cb"), new Annotation("service", "frontend"), new Annotation("parent", "00000000-0000-0000-0000-00000012d687"), new Annotation("component", "db"), new Annotation("application", "Custom-JaegerApp"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
expectLastCall();
mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(3456).setName("HTTP GET /").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-9a12-b85901d53397").setTraceId("00000000-0000-0000-fea4-87ee36e58cab").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("jaegerSpanId", "9a12b85901d53397"), new Annotation("jaegerTraceId", "fea487ee36e58cab"), new Annotation("service", "frontend"), new Annotation("parent", "00000000-0000-0000-fea4-87ee36e58cab"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
expectLastCall();
// Test filtering empty tags
mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(3456).setName("HTTP GET /test").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-0000-0051759bfc69").setTraceId("0000011e-ab2a-9944-0000-000049631900").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("jaegerSpanId", "51759bfc69"), new Annotation("jaegerTraceId", "11eab2a99440000000049631900"), new Annotation("service", "frontend"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
expectLastCall();
expect(mockCtx.write(EasyMock.isA(FullHttpResponse.class))).andReturn(null).anyTimes();
replay(mockTraceHandler, mockTraceSpanLogsHandler, mockCtx);
JaegerPortUnificationHandler handler = new JaegerPortUnificationHandler("14268", TokenAuthenticatorBuilder.create().build(), new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
Tag ipTag = new Tag("ip", TagType.STRING);
ipTag.setVStr("10.0.0.1");
Tag componentTag = new Tag("component", TagType.STRING);
componentTag.setVStr("db");
Tag customApplicationTag = new Tag("application", TagType.STRING);
customApplicationTag.setVStr("Custom-JaegerApp");
Tag emptyTag = new Tag("empty", TagType.STRING);
emptyTag.setVStr("");
io.jaegertracing.thriftjava.Span span1 = new io.jaegertracing.thriftjava.Span(1234567890123L, 1234567890L, 1234567L, 0L, "HTTP GET", 1, startTime * 1000, 1234 * 1000);
io.jaegertracing.thriftjava.Span span2 = new io.jaegertracing.thriftjava.Span(1234567890123L, 1234567890L, 2345678L, 1234567L, "HTTP GET /", 1, startTime * 1000, 2345 * 1000);
// check negative span IDs too
io.jaegertracing.thriftjava.Span span3 = new io.jaegertracing.thriftjava.Span(-97803834702328661L, 0L, -7344605349865507945L, -97803834702328661L, "HTTP GET /", 1, startTime * 1000, 3456 * 1000);
io.jaegertracing.thriftjava.Span span4 = new io.jaegertracing.thriftjava.Span(1231231232L, 1231232342340L, 349865507945L, 0, "HTTP GET /test", 1, startTime * 1000, 3456 * 1000);
span1.setTags(ImmutableList.of(componentTag));
span2.setTags(ImmutableList.of(componentTag, customApplicationTag));
span4.setTags(ImmutableList.of(emptyTag));
Tag tag1 = new Tag("event", TagType.STRING);
tag1.setVStr("error");
Tag tag2 = new Tag("exception", TagType.STRING);
tag2.setVStr("NullPointerException");
span1.setLogs(ImmutableList.of(new Log(startTime * 1000, ImmutableList.of(tag1, tag2))));
Batch testBatch = new Batch();
testBatch.process = new Process();
testBatch.process.serviceName = "frontend";
testBatch.process.setTags(ImmutableList.of(ipTag));
testBatch.setSpans(ImmutableList.of(span1, span2, span3, span4));
ByteBuf content = Unpooled.copiedBuffer(new TSerializer().serialize(testBatch));
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:14268/api/traces", content, true);
handler.handleHttpMessage(mockCtx, httpRequest);
verify(mockTraceHandler, mockTraceSpanLogsHandler);
}
use of io.jaegertracing.thriftjava.Log in project jaeger-client-java by jaegertracing.
the class JaegerThriftSpanConverter method buildLogs.
static List<Log> buildLogs(List<LogData> logs) {
List<Log> thriftLogs = new ArrayList<Log>();
if (logs != null) {
for (LogData logData : logs) {
Log thriftLog = new Log();
thriftLog.setTimestamp(logData.getTime());
if (logData.getFields() != null) {
thriftLog.setFields(buildTags(logData.getFields()));
} else {
List<Tag> tags = new ArrayList<Tag>();
if (logData.getMessage() != null) {
tags.add(buildTag("event", logData.getMessage()));
}
thriftLog.setFields(tags);
}
thriftLogs.add(thriftLog);
}
}
return thriftLogs;
}
use of io.jaegertracing.thriftjava.Log in project instrumentation-java by census-instrumentation.
the class JaegerExporterHandlerTest method exportShouldConvertFromSpanDataToJaegerThriftSpan.
@Test
public void exportShouldConvertFromSpanDataToJaegerThriftSpan() throws SenderException {
final long startTime = 1519629870001L;
final long endTime = 1519630148002L;
final SpanData spanData = SpanData.create(sampleSpanContext(), SpanId.fromBytes(new byte[] { (byte) 0x7F, FF, FF, FF, FF, FF, FF, FF }), true, "test", Kind.SERVER, Timestamp.fromMillis(startTime), SpanData.Attributes.create(sampleAttributes(), 0), SpanData.TimedEvents.create(singletonList(sampleAnnotation()), 0), SpanData.TimedEvents.create(singletonList(sampleMessageEvent()), 0), SpanData.Links.create(sampleLinks(), 0), 0, Status.OK, Timestamp.fromMillis(endTime));
handler.export(singletonList(spanData));
verify(mockSender).send(eq(process), captor.capture());
List<Span> spans = captor.getValue();
assertThat(spans.size()).isEqualTo(1);
Span span = spans.get(0);
assertThat(span.operationName).isEqualTo("test");
assertThat(span.spanId).isEqualTo(256L);
assertThat(span.traceIdHigh).isEqualTo(-72057594037927936L);
assertThat(span.traceIdLow).isEqualTo(1L);
assertThat(span.parentSpanId).isEqualTo(Long.MAX_VALUE);
assertThat(span.flags).isEqualTo(1);
assertThat(span.startTime).isEqualTo(MILLISECONDS.toMicros(startTime));
assertThat(span.duration).isEqualTo(MILLISECONDS.toMicros(endTime - startTime));
assertThat(span.tags.size()).isEqualTo(5);
assertThat(span.tags).containsExactly(new Tag("BOOL", TagType.BOOL).setVBool(false), new Tag("LONG", TagType.LONG).setVLong(Long.MAX_VALUE), new Tag(JaegerExporterHandler.SPAN_KIND, TagType.STRING).setVStr("server"), new Tag("STRING", TagType.STRING).setVStr("Judge of a man by his questions rather than by his answers. -- Voltaire"), new Tag(JaegerExporterHandler.STATUS_CODE, TagType.LONG).setVLong(0));
assertThat(span.logs.size()).isEqualTo(2);
Log log = span.logs.get(0);
assertThat(log.timestamp).isEqualTo(1519629872987654L);
assertThat(log.fields.size()).isEqualTo(4);
assertThat(log.fields).containsExactly(new Tag("message", TagType.STRING).setVStr("annotation #1"), new Tag("bool", TagType.BOOL).setVBool(true), new Tag("long", TagType.LONG).setVLong(1337L), new Tag("string", TagType.STRING).setVStr("Kind words do not cost much. Yet they accomplish much. -- Pascal"));
log = span.logs.get(1);
assertThat(log.timestamp).isEqualTo(1519629871123456L);
assertThat(log.fields.size()).isEqualTo(4);
assertThat(log.fields).containsExactly(new Tag("message", TagType.STRING).setVStr("sent message"), new Tag("id", TagType.LONG).setVLong(42L), new Tag("compressed_size", TagType.LONG).setVLong(69), new Tag("uncompressed_size", TagType.LONG).setVLong(96));
assertThat(span.references.size()).isEqualTo(1);
SpanRef reference = span.references.get(0);
assertThat(reference.traceIdHigh).isEqualTo(-1L);
assertThat(reference.traceIdLow).isEqualTo(-256L);
assertThat(reference.spanId).isEqualTo(512L);
assertThat(reference.refType).isEqualTo(SpanRefType.CHILD_OF);
}
Aggregations