use of io.opencensus.contrib.exemplar.util.AttachmentValueSpanContext in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtils method toProtoExemplar.
private static Exemplar toProtoExemplar(io.opencensus.metrics.data.Exemplar exemplar) {
Exemplar.Builder builder = Exemplar.newBuilder().setValue(exemplar.getValue()).setTimestamp(convertTimestamp(exemplar.getTimestamp()));
@javax.annotation.Nullable io.opencensus.trace.SpanContext spanContext = null;
for (Map.Entry<String, AttachmentValue> attachment : exemplar.getAttachments().entrySet()) {
String key = attachment.getKey();
AttachmentValue value = attachment.getValue();
if (ExemplarUtils.ATTACHMENT_KEY_SPAN_CONTEXT.equals(key)) {
spanContext = ((AttachmentValueSpanContext) value).getSpanContext();
} else {
// Everything else will be treated as plain strings for now.
builder.addAttachments(toProtoStringAttachment(value));
}
}
if (spanContext != null && cachedProjectIdForExemplar != null) {
SpanContext protoSpanContext = toProtoSpanContext(spanContext, cachedProjectIdForExemplar);
builder.addAttachments(toProtoSpanContextAttachment(protoSpanContext));
}
return builder.build();
}
Aggregations