Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ static AttributeKey<Double> doubleKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.DOUBLE);
}

/** Returns a new AttributeKey for {@link Attributes} (Map) valued attributes. */
static AttributeKey<Attributes> mapKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.MAP);
}

/** Returns a new AttributeKey for List&lt;String&gt; valued attributes. */
static AttributeKey<List<String>> stringArrayKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.STRING_ARRAY);
Expand All @@ -70,4 +75,14 @@ static AttributeKey<List<Long>> longArrayKey(String key) {
static AttributeKey<List<Double>> doubleArrayKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.DOUBLE_ARRAY);
}

/** Returns a new AttributeKey for List&lt;Attributes&gt; (List of Maps) valued attributes. */
static AttributeKey<List<Attributes>> mapArrayKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.MAP_ARRAY);
}

/** Returns a new AttributeKey for generic {@link Value} valued attributes. */
static AttributeKey<Value<?>> valueKey(String key) {
return InternalAttributeKeyImpl.create(key, AttributeType.VALUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ public enum AttributeType {
BOOLEAN,
LONG,
DOUBLE,
MAP,
STRING_ARRAY,
BOOLEAN_ARRAY,
LONG_ARRAY,
DOUBLE_ARRAY
DOUBLE_ARRAY,
MAP_ARRAY,
VALUE
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
import static io.opentelemetry.api.common.AttributeKey.doubleKey;
import static io.opentelemetry.api.common.AttributeKey.longArrayKey;
import static io.opentelemetry.api.common.AttributeKey.longKey;
import static io.opentelemetry.api.common.AttributeKey.mapArrayKey;
import static io.opentelemetry.api.common.AttributeKey.mapKey;
import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.api.common.AttributeKey.valueKey;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -91,6 +94,21 @@ default AttributesBuilder put(String key, boolean value) {
return put(booleanKey(key), value);
}

/**
* Puts an {@link Attributes} (Map) attribute into this.
*
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
* your keys, if possible.
*
* @return this Builder
*/
default <T> AttributesBuilder put(String key, Attributes value) {
if (value == null) {
return this;
}
return put(mapKey(key), value);
}

/**
* Puts a String array attribute into this.
*
Expand Down Expand Up @@ -164,6 +182,36 @@ default AttributesBuilder put(String key, boolean... value) {
return put(booleanArrayKey(key), toList(value));
}

/**
* Puts an {@link Attributes} array (List of Maps) attribute into this.
*
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
* your keys, if possible.
*
* @return this Builder
*/
default <T> AttributesBuilder put(String key, Attributes... value) {
if (value == null) {
return this;
}
return put(mapArrayKey(key), toList(value));
}

/**
* Puts a generic ({@link Value}) attribute into this.
*
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
* your keys, if possible.
*
* @return this Builder
*/
default AttributesBuilder put(String key, Value<?> value) {
if (value == null) {
return this;
}
return put(valueKey(key), value);
}

/**
* Puts all the provided attributes into this Builder.
*
Expand Down
Loading