Skip to content

Commit e39d49b

Browse files
committed
Prototype: Complex attributes (Option C - minimal)
1 parent 1c8db7d commit e39d49b

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@ static AttributeKey<List<Long>> longArrayKey(String key) {
7070
static AttributeKey<List<Double>> doubleArrayKey(String key) {
7171
return InternalAttributeKeyImpl.create(key, AttributeType.DOUBLE_ARRAY);
7272
}
73+
74+
/** Returns a new AttributeKey for generic {@link Value} valued attributes. */
75+
static AttributeKey<Value<?>> valueKey(String key) {
76+
return InternalAttributeKeyImpl.create(key, AttributeType.VALUE);
77+
}
7378
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ public enum AttributeType {
1717
STRING_ARRAY,
1818
BOOLEAN_ARRAY,
1919
LONG_ARRAY,
20-
DOUBLE_ARRAY
20+
DOUBLE_ARRAY,
21+
VALUE
2122
}

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

Lines changed: 18 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;
@@ -164,6 +167,21 @@ default AttributesBuilder put(String key, boolean... value) {
164167
return put(booleanArrayKey(key), toList(value));
165168
}
166169

170+
/**
171+
* Puts a generic ({@link Value}) attribute into this.
172+
*
173+
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
174+
* your keys, if possible.
175+
*
176+
* @return this Builder
177+
*/
178+
default AttributesBuilder put(String key, Value<?> value) {
179+
if (value == null) {
180+
return this;
181+
}
182+
return put(valueKey(key), value);
183+
}
184+
167185
/**
168186
* Puts all the provided attributes into this Builder.
169187
*

0 commit comments

Comments
 (0)