Search in sources :

Example 31 with SpanId

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();
}
Also used : Status(io.opencensus.trace.Status) AttributeValue(io.opencensus.trace.AttributeValue) SpanContext(io.opencensus.trace.SpanContext) SpanData(io.opencensus.trace.export.SpanData) Timestamp(io.opencensus.common.Timestamp) SpanId(io.opencensus.trace.SpanId)

Aggregations

SpanId (io.opencensus.trace.SpanId)31 Test (org.junit.Test)21 IgniteEx (org.apache.ignite.internal.IgniteEx)14 Transaction (org.apache.ignite.transactions.Transaction)10 TraceId (io.opencensus.trace.TraceId)6 TracingConfigurationParameters (org.apache.ignite.spi.tracing.TracingConfigurationParameters)6 TraceOptions (io.opencensus.trace.TraceOptions)5 TracingConfigurationCoordinates (org.apache.ignite.spi.tracing.TracingConfigurationCoordinates)5 SAMPLING_RATE_ALWAYS (org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS)5 SpanData (io.opencensus.trace.export.SpanData)4 SpanContextParseException (io.opencensus.trace.propagation.SpanContextParseException)4 Arrays (java.util.Arrays)4 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 SpanType (org.apache.ignite.internal.processors.tracing.SpanType)4 TracingSpi (org.apache.ignite.spi.tracing.TracingSpi)4 OpenCensusTracingSpi (org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi)4 Timestamp (io.opencensus.common.Timestamp)3 SpanContext (io.opencensus.trace.SpanContext)3