Search in sources :

Example 6 with Status

use of io.opencensus.trace.Status 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)

Example 7 with Status

use of io.opencensus.trace.Status in project instrumentation-java by census-instrumentation.

the class ZipkinExporterHandler method generateSpan.

@SuppressWarnings("deprecation")
static Span generateSpan(SpanData spanData, Endpoint localEndpoint) {
    SpanContext context = spanData.getContext();
    long startTimestamp = toEpochMicros(spanData.getStartTimestamp());
    // TODO(sebright): Fix the Checker Framework warning.
    @SuppressWarnings("nullness") long endTimestamp = toEpochMicros(spanData.getEndTimestamp());
    // TODO(bdrutu): Fix the Checker Framework warning.
    @SuppressWarnings("nullness") Span.Builder spanBuilder = Span.newBuilder().traceId(context.getTraceId().toLowerBase16()).id(context.getSpanId().toLowerBase16()).kind(toSpanKind(spanData)).name(spanData.getName()).timestamp(toEpochMicros(spanData.getStartTimestamp())).duration(endTimestamp - startTimestamp).localEndpoint(localEndpoint);
    if (spanData.getParentSpanId() != null && spanData.getParentSpanId().isValid()) {
        spanBuilder.parentId(spanData.getParentSpanId().toLowerBase16());
    }
    for (Map.Entry<String, AttributeValue> label : spanData.getAttributes().getAttributeMap().entrySet()) {
        spanBuilder.putTag(label.getKey(), attributeValueToString(label.getValue()));
    }
    Status status = spanData.getStatus();
    if (status != null) {
        spanBuilder.putTag(STATUS_CODE, status.getCanonicalCode().toString());
        if (status.getDescription() != null) {
            spanBuilder.putTag(STATUS_DESCRIPTION, status.getDescription());
        }
        if (!status.isOk()) {
            spanBuilder.putTag(STATUS_ERROR, status.getCanonicalCode().toString());
        }
    }
    for (TimedEvent<Annotation> annotation : spanData.getAnnotations().getEvents()) {
        spanBuilder.addAnnotation(toEpochMicros(annotation.getTimestamp()), annotation.getEvent().getDescription());
    }
    for (TimedEvent<io.opencensus.trace.MessageEvent> messageEvent : spanData.getMessageEvents().getEvents()) {
        spanBuilder.addAnnotation(toEpochMicros(messageEvent.getTimestamp()), messageEvent.getEvent().getType().name());
    }
    return spanBuilder.build();
}
Also used : Status(io.opencensus.trace.Status) AttributeValue(io.opencensus.trace.AttributeValue) SpanContext(io.opencensus.trace.SpanContext) Span(zipkin2.Span) Annotation(io.opencensus.trace.Annotation) Map(java.util.Map)

Example 8 with Status

use of io.opencensus.trace.Status in project instrumentation-java by census-instrumentation.

the class TimeLimitedHandler method handleException.

private static void handleException(Exception e, String logMessage) {
    Status status = e instanceof TimeoutException ? Status.DEADLINE_EXCEEDED : Status.UNKNOWN;
    tracer.getCurrentSpan().setStatus(status.withDescription(e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage()));
    logger.log(Level.WARNING, logMessage);
}
Also used : Status(io.opencensus.trace.Status) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Status (io.opencensus.trace.Status)8 AttributeValue (io.opencensus.trace.AttributeValue)4 SpanContext (io.opencensus.trace.SpanContext)4 Timestamp (io.opencensus.common.Timestamp)3 SpanData (io.opencensus.trace.export.SpanData)3 Annotation (io.opencensus.trace.Annotation)2 SpanId (io.opencensus.trace.SpanId)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TimeoutException (java.util.concurrent.TimeoutException)2 AttributeValue.stringAttributeValue (io.opencensus.trace.AttributeValue.stringAttributeValue)1 TimedEvent (io.opencensus.trace.export.SpanData.TimedEvent)1 Integer.parseInt (java.lang.Integer.parseInt)1 Calendar (java.util.Calendar)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 EventType (org.apache.ignite.events.EventType)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteFeatures (org.apache.ignite.internal.IgniteFeatures)1 MTC (org.apache.ignite.internal.processors.tracing.MTC)1