Skip to content

Commit a5e23ab

Browse files
committed
simplify
1 parent 23ad333 commit a5e23ab

File tree

4 files changed

+62
-15
lines changed

4 files changed

+62
-15
lines changed

api/all/src/main/java/io/opentelemetry/api/common/AttributeKey.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ static AttributeKey<Double> doubleKey(String key) {
5151
return InternalAttributeKeyImpl.create(key, AttributeType.DOUBLE);
5252
}
5353

54+
/** Returns a new AttributeKey for {@link Attributes} (Map) valued attributes. */
55+
static AttributeKey<Attributes> mapKey(String key) {
56+
return InternalAttributeKeyImpl.create(key, AttributeType.MAP);
57+
}
58+
5459
/** Returns a new AttributeKey for List&lt;String&gt; valued attributes. */
5560
static AttributeKey<List<String>> stringArrayKey(String key) {
5661
return InternalAttributeKeyImpl.create(key, AttributeType.STRING_ARRAY);
@@ -71,15 +76,13 @@ static AttributeKey<List<Double>> doubleArrayKey(String key) {
7176
return InternalAttributeKeyImpl.create(key, AttributeType.DOUBLE_ARRAY);
7277
}
7378

74-
static AttributeKey<byte[]> byteArrayKey(String key) {
75-
return InternalAttributeKeyImpl.create(key, AttributeType.BYTE_ARRAY);
79+
/** Returns a new AttributeKey for List&lt;Attributes&gt; (List of Maps) valued attributes. */
80+
static AttributeKey<List<Attributes>> mapArrayKey(String key) {
81+
return InternalAttributeKeyImpl.create(key, AttributeType.MAP_ARRAY);
7682
}
7783

78-
static AttributeKey<List<Value<?>>> valueArrayKey(String key) {
79-
return InternalAttributeKeyImpl.create(key, AttributeType.VALUE_ARRAY);
80-
}
81-
82-
static AttributeKey<Attributes> mapKey(String key) {
83-
return InternalAttributeKeyImpl.create(key, AttributeType.MAP);
84+
/** Returns a new AttributeKey for generic {@link Value} valued attributes. */
85+
static AttributeKey<Value<?>> valueKey(String key) {
86+
return InternalAttributeKeyImpl.create(key, AttributeType.VALUE);
8487
}
8588
}

api/all/src/main/java/io/opentelemetry/api/common/AttributeType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public enum AttributeType {
1414
BOOLEAN,
1515
LONG,
1616
DOUBLE,
17+
MAP,
1718
STRING_ARRAY,
1819
BOOLEAN_ARRAY,
1920
LONG_ARRAY,
2021
DOUBLE_ARRAY,
21-
BYTE_ARRAY,
22-
VALUE_ARRAY,
23-
MAP
22+
MAP_ARRAY,
23+
VALUE
2424
}

api/all/src/main/java/io/opentelemetry/api/common/AttributesBuilder.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
import static io.opentelemetry.api.common.AttributeKey.doubleKey;
1313
import static io.opentelemetry.api.common.AttributeKey.longArrayKey;
1414
import static io.opentelemetry.api.common.AttributeKey.longKey;
15+
import static io.opentelemetry.api.common.AttributeKey.mapArrayKey;
16+
import static io.opentelemetry.api.common.AttributeKey.mapKey;
1517
import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
1618
import static io.opentelemetry.api.common.AttributeKey.stringKey;
19+
import static io.opentelemetry.api.common.AttributeKey.valueKey;
1720

1821
import java.util.Arrays;
1922
import java.util.List;
@@ -91,6 +94,21 @@ default AttributesBuilder put(String key, boolean value) {
9194
return put(booleanKey(key), value);
9295
}
9396

97+
/**
98+
* Puts an {@link Attributes} (Map) attribute into this.
99+
*
100+
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
101+
* your keys, if possible.
102+
*
103+
* @return this Builder
104+
*/
105+
default <T> AttributesBuilder put(String key, Attributes value) {
106+
if (value == null) {
107+
return this;
108+
}
109+
return put(mapKey(key), value);
110+
}
111+
94112
/**
95113
* Puts a String array attribute into this.
96114
*
@@ -164,6 +182,36 @@ default AttributesBuilder put(String key, boolean... value) {
164182
return put(booleanArrayKey(key), toList(value));
165183
}
166184

185+
/**
186+
* Puts an {@link Attributes} array (List of Maps) attribute into this.
187+
*
188+
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
189+
* your keys, if possible.
190+
*
191+
* @return this Builder
192+
*/
193+
default <T> AttributesBuilder put(String key, Attributes... value) {
194+
if (value == null) {
195+
return this;
196+
}
197+
return put(mapArrayKey(key), toList(value));
198+
}
199+
200+
/**
201+
* Puts a generic ({@link Value}) attribute into this.
202+
*
203+
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
204+
* your keys, if possible.
205+
*
206+
* @return this Builder
207+
*/
208+
default AttributesBuilder put(String key, Value<?> value) {
209+
if (value == null) {
210+
return this;
211+
}
212+
return put(valueKey(key), value);
213+
}
214+
167215
/**
168216
* Puts all the provided attributes into this Builder.
169217
*

api/all/src/main/java/io/opentelemetry/api/common/Value.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ static Value<List<KeyValue>> of(Map<String, Value<?>> value) {
8484
return KeyValueList.createFromMap(value);
8585
}
8686

87-
static Value<List<KeyValue>> of(Attributes attributes) {
88-
// TODO
89-
}
90-
9187
/** Returns the type of this {@link Value}. Useful for building switch statements. */
9288
ValueType getType();
9389

0 commit comments

Comments
 (0)