use of io.opencensus.trace.SpanId 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();
}
Aggregations