use of io.opencensus.tags.TagKey in project instrumentation-java by census-instrumentation.
the class BinarySerializationUtils method parseTags.
private static Map<TagKey, TagValueWithMetadata> parseTags(ByteBuffer buffer) throws TagContextDeserializationException {
Map<TagKey, TagValueWithMetadata> tags = new HashMap<TagKey, TagValueWithMetadata>();
int limit = buffer.limit();
// Here chars are equivalent to bytes, since we're using ascii chars.
int totalChars = 0;
while (buffer.position() < limit) {
int type = buffer.get();
if (type == TAG_FIELD_ID) {
TagKey key = createTagKey(decodeString(buffer));
TagValue val = createTagValue(key, decodeString(buffer));
totalChars += key.getName().length();
totalChars += val.asString().length();
tags.put(key, TagValueWithMetadata.create(val, METADATA_UNLIMITED_PROPAGATION));
} else {
// TODO(sebright): Consider storing the rest of the byte array in the TagContext.
break;
}
}
if (totalChars > TAGCONTEXT_SERIALIZED_SIZE_LIMIT) {
throw new TagContextDeserializationException("Size of TagContext exceeds the maximum serialized size " + TAGCONTEXT_SERIALIZED_SIZE_LIMIT);
}
return tags;
}
use of io.opencensus.tags.TagKey in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormat method decodeTag.
// Decodes tag key, value and metadata from the encoded string tag, then puts it into the tag map.
// The format of encoded string tag is name1=value1;properties1=p1;properties2=p2.
private static void decodeTag(String stringTag, Map<TagKey, TagValueWithMetadata> tags) {
String keyWithValue;
int firstPropertyIndex = stringTag.indexOf(TAG_PROPERTIES_DELIMITER);
if (firstPropertyIndex != -1) {
// Tag with properties.
keyWithValue = stringTag.substring(0, firstPropertyIndex);
// TODO(songya): support decoding tag properties.
} else {
// Tag without properties.
keyWithValue = stringTag;
}
List<String> keyValuePair = TAG_KEY_VALUE_SPLITTER.splitToList(keyWithValue);
checkArgument(keyValuePair.size() == 2, "Malformed tag " + stringTag);
TagKey key = TagKey.create(keyValuePair.get(0).trim());
TagValue value = TagValue.create(keyValuePair.get(1).trim());
TagValueWithMetadata valueWithMetadata = TagValueWithMetadata.create(value, METADATA_UNLIMITED_PROPAGATION);
tags.put(key, valueWithMetadata);
}
use of io.opencensus.tags.TagKey in project instrumentation-java by census-instrumentation.
the class RecordUtils method getTagValues.
@VisibleForTesting
static List</*@Nullable*/
TagValue> getTagValues(Map<? extends TagKey, TagValueWithMetadata> tags, List<? extends TagKey> columns) {
List<TagValue> /*@Nullable*/
tagValues = new ArrayList</*@Nullable*/
TagValue>(columns.size());
// Every view aggregates every measure. This is similar to doing a GROUPBY view’s keys.
for (int i = 0; i < columns.size(); ++i) {
TagKey tagKey = columns.get(i);
if (!tags.containsKey(tagKey)) {
@javax.annotation.Nullable TagValue tagValue = UNKNOWN_TAG_VALUE;
TagKey[] newKeys = RPC_TAG_MAPPINGS.get(tagKey);
if (newKeys != null) {
tagValue = getTagValueForDeprecatedRpcTag(tags, newKeys);
}
tagValues.add(tagValue);
} else {
tagValues.add(tags.get(tagKey).getTagValue());
}
}
return tagValues;
}
use of io.opencensus.tags.TagKey in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testViewDataWithMultipleTagKeys.
@Test
public void testViewDataWithMultipleTagKeys() {
TagKey key1 = TagKey.create("Key-1");
TagKey key2 = TagKey.create("Key-2");
viewManager.registerView(createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(key1, key2)));
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(key1, TagValue.create("v1")).put(key2, TagValue.create("v10")).build());
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 2.2).record(tagger.emptyBuilder().put(key1, TagValue.create("v1")).put(key2, TagValue.create("v20")).build());
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 3.3).record(tagger.emptyBuilder().put(key1, TagValue.create("v2")).put(key2, TagValue.create("v10")).build());
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 4.4).record(tagger.emptyBuilder().put(key1, TagValue.create("v1")).put(key2, TagValue.create("v10")).build());
ViewData viewData = viewManager.getView(VIEW_NAME);
assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(TagValue.create("v1"), TagValue.create("v10")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 1.1, 4.4), Arrays.asList(TagValue.create("v1"), TagValue.create("v20")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 2.2), Arrays.asList(TagValue.create("v2"), TagValue.create("v10")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 3.3)), EPSILON);
}
Aggregations