Search in sources :

Example 1 with AttachmentValue

use of io.opencensus.metrics.data.AttachmentValue in project instrumentation-java by census-instrumentation.

the class MeasureToViewMap method record.

// Records stats with a set of tags.
synchronized void record(TagContext tags, MeasureMapInternal stats, Timestamp timestamp) {
    Iterator<Measurement> iterator = stats.iterator();
    Map<String, AttachmentValue> attachments = stats.getAttachments();
    while (iterator.hasNext()) {
        Measurement measurement = iterator.next();
        Measure measure = measurement.getMeasure();
        if (!measure.equals(registeredMeasures.get(measure.getName()))) {
            // unregistered measures will be ignored.
            continue;
        }
        Collection<MutableViewData> viewDataCollection = mutableMap.get(measure.getName());
        for (MutableViewData viewData : viewDataCollection) {
            viewData.record(tags, RecordUtils.getDoubleValueFromMeasurement(measurement), timestamp, attachments);
        }
    }
}
Also used : Measurement(io.opencensus.stats.Measurement) AttachmentValue(io.opencensus.metrics.data.AttachmentValue) Measure(io.opencensus.stats.Measure)

Example 2 with AttachmentValue

use of io.opencensus.metrics.data.AttachmentValue 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();
}
Also used : AttachmentValue(io.opencensus.metrics.data.AttachmentValue) Exemplar(com.google.api.Distribution.Exemplar) SpanContext(com.google.monitoring.v3.SpanContext) AttachmentValueSpanContext(io.opencensus.contrib.exemplar.util.AttachmentValueSpanContext) ByteString(com.google.protobuf.ByteString) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

AttachmentValue (io.opencensus.metrics.data.AttachmentValue)2 Exemplar (com.google.api.Distribution.Exemplar)1 SpanContext (com.google.monitoring.v3.SpanContext)1 ByteString (com.google.protobuf.ByteString)1 AttachmentValueSpanContext (io.opencensus.contrib.exemplar.util.AttachmentValueSpanContext)1 Measure (io.opencensus.stats.Measure)1 Measurement (io.opencensus.stats.Measurement)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1