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();
}
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();
}
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);
}
Aggregations