use of io.opencensus.implcore.tags.TagMapImpl in project instrumentation-java by census-instrumentation.
the class RecordUtils method getTagMap.
static Map<TagKey, TagValueWithMetadata> getTagMap(TagContext ctx) {
if (ctx instanceof TagMapImpl) {
return ((TagMapImpl) ctx).getTags();
}
Map<TagKey, TagValueWithMetadata> tags = Maps.newHashMap();
for (Iterator<Tag> i = InternalUtils.getTags(ctx); i.hasNext(); ) {
Tag tag = i.next();
tags.put(tag.getKey(), TagValueWithMetadata.create(tag.getValue(), tag.getTagMetadata()));
}
return tags;
}
use of io.opencensus.implcore.tags.TagMapImpl in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormat method extract.
@Override
public <C> /*>>> extends @NonNull Object*/
TagContext extract(C carrier, Getter<C> getter) throws TagContextDeserializationException {
checkNotNull(carrier, "carrier");
checkNotNull(getter, "getter");
if (State.DISABLED.equals(state.getInternal())) {
return TagMapImpl.EMPTY;
}
@Nullable String correlationContext = getter.get(carrier, CORRELATION_CONTEXT);
if (correlationContext == null) {
throw new TagContextDeserializationException(CORRELATION_CONTEXT + " not present.");
}
try {
if (correlationContext.isEmpty()) {
return TagMapImpl.EMPTY;
}
Map<TagKey, TagValueWithMetadata> tags = new HashMap<>();
List<String> stringTags = TAG_SPLITTER.splitToList(correlationContext);
for (String stringTag : stringTags) {
decodeTag(stringTag, tags);
}
return new TagMapImpl(tags);
} catch (IllegalArgumentException e) {
throw new TagContextDeserializationException("Invalid TagContext: " + correlationContext, e);
}
}
use of io.opencensus.implcore.tags.TagMapImpl in project instrumentation-java by census-instrumentation.
the class BinarySerializationUtils method deserializeBinary.
// Deserializes input to TagContext based on the binary format standard.
// The encoded tags are of the form: <version_id><encoded_tags>
static TagMapImpl deserializeBinary(byte[] bytes) throws TagContextDeserializationException {
try {
if (bytes.length == 0) {
// Does not allow empty byte array.
throw new TagContextDeserializationException("Input byte[] can not be empty.");
}
ByteBuffer buffer = ByteBuffer.wrap(bytes).asReadOnlyBuffer();
int versionId = buffer.get();
if (versionId > VERSION_ID || versionId < 0) {
throw new TagContextDeserializationException("Wrong Version ID: " + versionId + ". Currently supports version up to: " + VERSION_ID);
}
return new TagMapImpl(parseTags(buffer));
} catch (BufferUnderflowException exn) {
// byte array format error.
throw new TagContextDeserializationException(exn.toString());
}
}
Aggregations