Skip to content

Commit ddfe54a

Browse files
committed
simplify
1 parent 23ad333 commit ddfe54a

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,11 @@ static AttributeKey<List<Double>> doubleArrayKey(String key) {
7171
return InternalAttributeKeyImpl.create(key, AttributeType.DOUBLE_ARRAY);
7272
}
7373

74-
static AttributeKey<byte[]> byteArrayKey(String key) {
75-
return InternalAttributeKeyImpl.create(key, AttributeType.BYTE_ARRAY);
76-
}
77-
78-
static AttributeKey<List<Value<?>>> valueArrayKey(String key) {
79-
return InternalAttributeKeyImpl.create(key, AttributeType.VALUE_ARRAY);
80-
}
81-
8274
static AttributeKey<Attributes> mapKey(String key) {
8375
return InternalAttributeKeyImpl.create(key, AttributeType.MAP);
8476
}
77+
78+
static AttributeKey<Value<?>> valueKey(String key) {
79+
return InternalAttributeKeyImpl.create(key, AttributeType.VALUE);
80+
}
8581
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public enum AttributeType {
1818
BOOLEAN_ARRAY,
1919
LONG_ARRAY,
2020
DOUBLE_ARRAY,
21-
BYTE_ARRAY,
22-
VALUE_ARRAY,
23-
MAP
21+
MAP,
22+
VALUE
2423
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
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.mapKey;
1516
import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
1617
import static io.opentelemetry.api.common.AttributeKey.stringKey;
18+
import static io.opentelemetry.api.common.AttributeKey.valueKey;
1719

1820
import java.util.Arrays;
1921
import java.util.List;
@@ -164,6 +166,36 @@ default AttributesBuilder put(String key, boolean... value) {
164166
return put(booleanArrayKey(key), toList(value));
165167
}
166168

169+
/**
170+
* Puts a nested map ({@link Attributes}) attribute into this.
171+
*
172+
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
173+
* your keys, if possible.
174+
*
175+
* @return this Builder
176+
*/
177+
default <T> AttributesBuilder put(String key, Attributes value) {
178+
if (value == null) {
179+
return this;
180+
}
181+
return put(mapKey(key), value);
182+
}
183+
184+
/**
185+
* Puts a generic ({@link Value}) attribute into this.
186+
*
187+
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
188+
* your keys, if possible.
189+
*
190+
* @return this Builder
191+
*/
192+
default AttributesBuilder put(String key, Value<?> value) {
193+
if (value == null) {
194+
return this;
195+
}
196+
return put(valueKey(key), value);
197+
}
198+
167199
/**
168200
* Puts all the provided attributes into this Builder.
169201
*

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)