use of io.opencensus.trace.export.SpanData 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);
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class DatadogExporterHandlerTest method testNullableConversion.
@Test
public void testNullableConversion() {
SpanData data = SpanData.create(SpanContext.create(TraceId.fromLowerBase16(TRACE_ID), SpanId.fromLowerBase16(SPAN_ID), TraceOptions.builder().setIsSampled(true).build(), Tracestate.builder().build()), /* parentSpanId= */
null, /* hasRemoteParent= */
false, "SpanName", /* kind= */
null, /* startTimestamp= */
Timestamp.create(1505855794, 194009601), SpanData.Attributes.create(attributes, 0), SpanData.TimedEvents.create(annotations, 0), SpanData.TimedEvents.create(messageEvents, 0), SpanData.Links.create(Collections.emptyList(), 0), /* childSpanCount= */
null, /* status= */
null, /* endTimestamp= */
null);
final String expected = "[[" + "{" + "\"trace_id\":3298601478987650031," + "\"span_id\":7151185124527981047," + "\"name\":\"SpanName\"," + "\"resource\":\"/foo\"," + "\"service\":\"service\"," + "\"type\":\"web\"," + "\"start\":1505855794194009601," + // the tracer clock is set to 0 in tests
"\"duration\":-1505855794194009601," + "\"error\":0," + "\"meta\":{" + "\"resource\":\"/foo\"," + "\"http.url\":\"http://localhost/foo\"" + "}" + "}" + "]]";
assertThat(handler.convertToJson(Collections.singletonList(data))).isEqualTo(expected);
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class InstanaExporterHandler method convertToJson.
static String convertToJson(Collection<SpanData> spanDataList) {
StringBuilder sb = new StringBuilder();
sb.append('[');
for (final SpanData span : spanDataList) {
final SpanContext spanContext = span.getContext();
final SpanId parentSpanId = span.getParentSpanId();
final Timestamp startTimestamp = span.getStartTimestamp();
final Timestamp endTimestamp = span.getEndTimestamp();
final Status status = span.getStatus();
if (status == null || endTimestamp == null) {
continue;
}
if (sb.length() > 1) {
sb.append(',');
}
sb.append('{');
sb.append("\"spanId\":\"").append(encodeSpanId(spanContext.getSpanId())).append("\",");
sb.append("\"traceId\":\"").append(encodeTraceId(spanContext.getTraceId())).append("\",");
if (parentSpanId != null) {
sb.append("\"parentId\":\"").append(encodeSpanId(parentSpanId)).append("\",");
}
sb.append("\"timestamp\":").append(toMillis(startTimestamp)).append(',');
sb.append("\"duration\":").append(toMillis(startTimestamp, endTimestamp)).append(',');
sb.append("\"name\":\"").append(toSpanName(span)).append("\",");
sb.append("\"type\":\"").append(toSpanType(span)).append('"');
if (!status.isOk()) {
sb.append(",\"error\":").append("true");
}
Map<String, AttributeValue> attributeMap = span.getAttributes().getAttributeMap();
if (attributeMap.size() > 0) {
StringBuilder dataSb = new StringBuilder();
dataSb.append('{');
for (Entry<String, AttributeValue> entry : attributeMap.entrySet()) {
if (dataSb.length() > 1) {
dataSb.append(',');
}
dataSb.append("\"").append(entry.getKey()).append("\":\"").append(attributeValueToString(entry.getValue())).append("\"");
}
dataSb.append('}');
sb.append(",\"data\":").append(dataSb);
}
sb.append('}');
}
sb.append(']');
return sb.toString();
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class InstanaExporterHandlerTest method generateSpan_MultipleSpans.
@Test
public void generateSpan_MultipleSpans() {
SpanData data = SpanData.create(SpanContext.create(TraceId.fromLowerBase16(TRACE_ID), SpanId.fromLowerBase16(SPAN_ID), TraceOptions.builder().setIsSampled(true).build()), SpanId.fromLowerBase16(PARENT_SPAN_ID), true, /* hasRemoteParent */
"SpanName", /* name */
Kind.CLIENT, /* kind */
Timestamp.create(1505855794, 194009601), /* startTimestamp */
Attributes.create(attributes, 0), TimedEvents.create(annotations, 0), TimedEvents.create(messageEvents, 0), Links.create(Collections.<Link>emptyList(), 0), null, /* childSpanCount */
Status.OK, Timestamp.create(1505855799, 465726528));
assertThat(InstanaExporterHandler.convertToJson(Collections.nCopies(2, data))).isEqualTo("[" + "{" + "\"spanId\":\"9cc1e3049173be09\"," + "\"traceId\":\"d239036e7d5cec11\"," + "\"parentId\":\"8b03ab423da481c5\"," + "\"timestamp\":1505855794194," + "\"duration\":5271," + "\"name\":\"SpanName\"," + "\"type\":\"EXIT\"," + "\"data\":" + "{\"http.url\":\"http://localhost/foo\"}" + "}," + "{" + "\"spanId\":\"9cc1e3049173be09\"," + "\"traceId\":\"d239036e7d5cec11\"," + "\"parentId\":\"8b03ab423da481c5\"," + "\"timestamp\":1505855794194," + "\"duration\":5271," + "\"name\":\"SpanName\"," + "\"type\":\"EXIT\"," + "\"data\":" + "{\"http.url\":\"http://localhost/foo\"}" + "}" + "]");
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class StackdriverV2ExporterHandlerProtoTest method generateSpanName_ForClient.
@Test
public void generateSpanName_ForClient() {
SpanData spanData = SpanData.create(spanContext, parentSpanId, /* hasRemoteParent= */
true, SPAN_NAME, Kind.CLIENT, startTimestamp, attributes, annotations, messageEvents, links, CHILD_SPAN_COUNT, status, endTimestamp);
assertThat(handler.generateSpan(spanData, EMPTY_RESOURCE_LABELS, Collections.<String, AttributeValue>emptyMap()).getDisplayName().getValue()).isEqualTo("Sent." + SPAN_NAME);
}
Aggregations