From e2a9dd9fc04a3e488651848db10d6f9de72ea84e Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 4 Nov 2025 09:53:27 -0800 Subject: [PATCH 1/2] Rename EXTENDED_ATTRIBUTES to MAP --- .../api/incubator/common/ExtendedAttributeKey.java | 6 +++--- .../incubator/common/ExtendedAttributeType.java | 2 +- .../api/incubator/common/ExtendedAttributes.java | 3 +-- .../common/ExtendedAttributesBuilder.java | 2 +- .../internal/InternalExtendedAttributeKeyImpl.java | 2 +- .../incubator/common/ExtendedAttributeKeyTest.java | 6 +----- .../incubator/common/ExtendedAttributesTest.java | 14 +++++++------- .../logs/ExtendedLogsBridgeApiUsageTest.java | 5 ++--- ...xtendedAttributeKeyValueStatelessMarshaler.java | 4 ++-- .../exporter/internal/otlp/IncubatingUtil.java | 2 +- 10 files changed, 20 insertions(+), 26 deletions(-) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java index 13357a31a56..ca2c672e96e 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java @@ -93,8 +93,8 @@ static ExtendedAttributeKey> doubleArrayKey(String key) { return fromAttributeKey(AttributeKey.doubleArrayKey(key)); } - /** Returns a new ExtendedAttributeKey for Map valued attributes. */ - static ExtendedAttributeKey extendedAttributesKey(String key) { - return InternalExtendedAttributeKeyImpl.create(key, ExtendedAttributeType.EXTENDED_ATTRIBUTES); + /** Returns a new ExtendedAttributeKey for map valued attributes. */ + static ExtendedAttributeKey mapKey(String key) { + return InternalExtendedAttributeKeyImpl.create(key, ExtendedAttributeType.MAP); } } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java index 8d2c67181b6..47266099b9a 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java @@ -22,5 +22,5 @@ public enum ExtendedAttributeType { LONG_ARRAY, DOUBLE_ARRAY, // Extended types unique to ExtendedAttributes - EXTENDED_ATTRIBUTES; + MAP; } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java index 0fc88a2ea49..96a6713ddb2 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java @@ -18,8 +18,7 @@ * *

"extended" refers an extended set of allowed value types compared to standard {@link * Attributes}. Notably, {@link ExtendedAttributes} values can be of type {@link - * ExtendedAttributeType#EXTENDED_ATTRIBUTES}, allowing nested {@link ExtendedAttributes} of - * arbitrary depth. + * ExtendedAttributeType#MAP}, allowing nested {@link ExtendedAttributes} of arbitrary depth. * *

Where standard {@link Attributes} are accepted everyone that OpenTelemetry represents key / * value pairs, {@link ExtendedAttributes} are only accepted in select places, such as log records diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java index 1e0de3b4c38..9089d08e643 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java @@ -94,7 +94,7 @@ default ExtendedAttributesBuilder put(String key, boolean value) { * @return this Builder */ default ExtendedAttributesBuilder put(String key, ExtendedAttributes value) { - return put(ExtendedAttributeKey.extendedAttributesKey(key), value); + return put(ExtendedAttributeKey.mapKey(key), value); } /** diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java index e07f72f0121..c389a745230 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java @@ -138,7 +138,7 @@ public static AttributeKey toAttributeKey(ExtendedAttributeKey extende case DOUBLE_ARRAY: return InternalAttributeKeyImpl.create( extendedAttributeKey.getKey(), AttributeType.DOUBLE_ARRAY); - case EXTENDED_ATTRIBUTES: + case MAP: return null; } throw new IllegalArgumentException( diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKeyTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKeyTest.java index d2f77625d1f..44e4335d572 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKeyTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKeyTest.java @@ -76,10 +76,6 @@ private static Stream attributeKeyArgs() { "key", ExtendedAttributeType.DOUBLE_ARRAY, AttributeKey.doubleArrayKey("key")), - Arguments.of( - ExtendedAttributeKey.extendedAttributesKey("key"), - "key", - ExtendedAttributeType.EXTENDED_ATTRIBUTES, - null)); + Arguments.of(ExtendedAttributeKey.mapKey("key"), "key", ExtendedAttributeType.MAP, null)); } } diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java index 4481cead3d0..6030779cf5d 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java @@ -95,7 +95,7 @@ private static void assertEquals( assertThat(actual.size()).isEqualTo(expected.size()); actual.forEach( (key, value) -> { - if (key.getType() == ExtendedAttributeType.EXTENDED_ATTRIBUTES) { + if (key.getType() == ExtendedAttributeType.MAP) { assertEquals( ((ExtendedAttributes) value).asMap(), (Map) expected.get(key.getKey())); @@ -161,7 +161,7 @@ private static ExtendedAttributes fromMap(Map map) { map.forEach( (key, value) -> { ExtendedAttributeKey extendedAttributeKey = getKey(key, value); - if (extendedAttributeKey.getType() == ExtendedAttributeType.EXTENDED_ATTRIBUTES) { + if (extendedAttributeKey.getType() == ExtendedAttributeType.MAP) { builder.put( (ExtendedAttributeKey) extendedAttributeKey, fromMap((Map) value)); @@ -249,7 +249,7 @@ private static Stream attributesArgs() { Arguments.of( ExtendedAttributes.builder() .put( - ExtendedAttributeKey.extendedAttributesKey("key"), + ExtendedAttributeKey.mapKey("key"), ExtendedAttributes.builder().put("child", "value").build()) .build(), ImmutableMap.builder() @@ -287,7 +287,7 @@ private static Map toMap(ExtendedAttributes extendedAttributes) Map map = new HashMap<>(); extendedAttributes.forEach( (key, value) -> { - if (key.getType() == ExtendedAttributeType.EXTENDED_ATTRIBUTES) { + if (key.getType() == ExtendedAttributeType.MAP) { map.put(key.getKey(), toMap((ExtendedAttributes) value)); return; } @@ -314,8 +314,8 @@ private static ExtendedAttributeKey getKey(String key, Object value) { return ExtendedAttributeKey.longArrayKey(key); case DOUBLE_ARRAY: return ExtendedAttributeKey.doubleArrayKey(key); - case EXTENDED_ATTRIBUTES: - return ExtendedAttributeKey.extendedAttributesKey(key); + case MAP: + return ExtendedAttributeKey.mapKey(key); } throw new IllegalArgumentException(); } @@ -353,7 +353,7 @@ private static ExtendedAttributeType getType(Object value) { } } if ((value instanceof Map)) { - return ExtendedAttributeType.EXTENDED_ATTRIBUTES; + return ExtendedAttributeType.MAP; } throw new IllegalArgumentException("Unrecognized value type: " + value); } diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java index 05c3e65f859..a99ce97d9d0 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java @@ -104,8 +104,7 @@ private static String flipCoin() { AttributeKey> doubleArrKey = AttributeKey.doubleArrayKey("acme.double_array"); // Extended keys - ExtendedAttributeKey mapKey = - ExtendedAttributeKey.extendedAttributesKey("acme.map"); + ExtendedAttributeKey mapKey = ExtendedAttributeKey.mapKey("acme.map"); @Test @SuppressLogger(ExtendedLogsBridgeApiUsageTest.class) @@ -148,7 +147,7 @@ void extendedAttributesUsage() { // acme.double_array(DOUBLE_ARRAY): [1.1, 2.2] // acme.long(LONG): 1 // acme.long_array(LONG_ARRAY): [1, 2] - // acme.map(EXTENDED_ATTRIBUTES): {childLong=1, childStr="value"} + // acme.map(MAP): {childLong=1, childStr="value"} // acme.string(STRING): value // acme.string_array(STRING_ARRAY): [value1, value2] extendedAttributes.forEach( diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java index de31139abcb..0d2f811ee37 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java @@ -168,7 +168,7 @@ public int getBinarySerializedSize( (List) value, AttributeArrayAnyValueStatelessMarshaler.INSTANCE, context); - case EXTENDED_ATTRIBUTES: + case MAP: return StatelessMarshalerUtil.sizeMessageWithContext( AnyValue.KVLIST_VALUE, (ExtendedAttributes) value, @@ -213,7 +213,7 @@ public void writeTo( AttributeArrayAnyValueStatelessMarshaler.INSTANCE, context); return; - case EXTENDED_ATTRIBUTES: + case MAP: output.serializeMessageWithContext( AnyValue.KVLIST_VALUE, (ExtendedAttributes) value, diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java index 90660fd5a85..552fd3c7f4c 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java @@ -110,7 +110,7 @@ private static KeyValueMarshaler create(ExtendedAttributeKey attributeKey, Ob case DOUBLE_ARRAY: return new KeyValueMarshaler( keyUtf8, ArrayAnyValueMarshaler.createDouble((List) value)); - case EXTENDED_ATTRIBUTES: + case MAP: return new KeyValueMarshaler( keyUtf8, new KeyValueListAnyValueMarshaler( From 1a1101a66d588b7059cba8374b8aadf7333c460a Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 4 Nov 2025 15:29:03 -0800 Subject: [PATCH 2/2] Complex attributes incubating support --- .../common/ExtendedAttributeKey.java | 6 ++++++ .../common/ExtendedAttributeType.java | 3 ++- .../incubator/common/ExtendedAttributes.java | 4 +++- .../common/ExtendedAttributesBuilder.java | 16 +++++++++++++++ .../InternalExtendedAttributeKeyImpl.java | 1 + .../common/ExtendedAttributeKeyTest.java | 4 +++- .../common/ExtendedAttributesTest.java | 20 ++++++++++++++++++- .../logs/ExtendedLogsBridgeApiUsageTest.java | 7 +++++++ ...edAttributeKeyValueStatelessMarshaler.java | 7 +++++++ .../internal/otlp/IncubatingUtil.java | 3 +++ 10 files changed, 67 insertions(+), 4 deletions(-) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java index ca2c672e96e..2af87227df5 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java @@ -6,6 +6,7 @@ package io.opentelemetry.api.incubator.common; import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Value; import io.opentelemetry.api.incubator.internal.InternalExtendedAttributeKeyImpl; import java.util.List; import javax.annotation.Nullable; @@ -97,4 +98,9 @@ static ExtendedAttributeKey> doubleArrayKey(String key) { static ExtendedAttributeKey mapKey(String key) { return InternalExtendedAttributeKeyImpl.create(key, ExtendedAttributeType.MAP); } + + /** Returns a new ExtendedAttributeKey for {@link Value} valued attributes. */ + static ExtendedAttributeKey> valueKey(String key) { + return InternalExtendedAttributeKeyImpl.create(key, ExtendedAttributeType.VALUE); + } } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java index 47266099b9a..7b026bb2a1b 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java @@ -22,5 +22,6 @@ public enum ExtendedAttributeType { LONG_ARRAY, DOUBLE_ARRAY, // Extended types unique to ExtendedAttributes - MAP; + MAP, + VALUE; } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java index 96a6713ddb2..4fa3b278b46 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java @@ -18,7 +18,9 @@ * *

"extended" refers an extended set of allowed value types compared to standard {@link * Attributes}. Notably, {@link ExtendedAttributes} values can be of type {@link - * ExtendedAttributeType#MAP}, allowing nested {@link ExtendedAttributes} of arbitrary depth. + * ExtendedAttributeType#MAP}, allowing nested {@link ExtendedAttributes} of arbitrary depth, or + * {@link ExtendedAttributeType#VALUE}, enabling usage of {@link io.opentelemetry.api.common.Value} + * instances. * *

Where standard {@link Attributes} are accepted everyone that OpenTelemetry represents key / * value pairs, {@link ExtendedAttributes} are only accepted in select places, such as log records diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java index 9089d08e643..8fba43e4c67 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java @@ -17,6 +17,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.Value; import java.util.Arrays; import java.util.List; import java.util.function.Predicate; @@ -97,6 +98,21 @@ default ExtendedAttributesBuilder put(String key, ExtendedAttributes value) return put(ExtendedAttributeKey.mapKey(key), value); } + /** + * Puts a {@link Value} attribute into this. + * + *

Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and + * pre-allocate your keys, if possible. + * + * @return this Builder + */ + default ExtendedAttributesBuilder put(String key, Value value) { + if (value == null) { + return this; + } + return put(ExtendedAttributeKey.valueKey(key), value); + } + /** * Puts a String array attribute into this. * diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java index c389a745230..d863c5765b5 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java @@ -139,6 +139,7 @@ public static AttributeKey toAttributeKey(ExtendedAttributeKey extende return InternalAttributeKeyImpl.create( extendedAttributeKey.getKey(), AttributeType.DOUBLE_ARRAY); case MAP: + case VALUE: return null; } throw new IllegalArgumentException( diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKeyTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKeyTest.java index 44e4335d572..1c4c546f17a 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKeyTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKeyTest.java @@ -76,6 +76,8 @@ private static Stream attributeKeyArgs() { "key", ExtendedAttributeType.DOUBLE_ARRAY, AttributeKey.doubleArrayKey("key")), - Arguments.of(ExtendedAttributeKey.mapKey("key"), "key", ExtendedAttributeType.MAP, null)); + Arguments.of(ExtendedAttributeKey.mapKey("key"), "key", ExtendedAttributeType.MAP, null), + Arguments.of( + ExtendedAttributeKey.valueKey("key"), "key", ExtendedAttributeType.VALUE, null)); } } diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java index 6030779cf5d..4e5c96a62f7 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java @@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableMap; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.Value; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -116,7 +117,9 @@ void asAttributes(ExtendedAttributes extendedAttributes, Map exp }); long expectedSize = - expectedMap.values().stream().filter(value -> !(value instanceof Map)).count(); + expectedMap.values().stream() + .filter(value -> !(value instanceof Map) && !(value instanceof Value)) + .count(); assertThat(attributes.size()).isEqualTo(expectedSize); } @@ -212,6 +215,9 @@ private static Stream attributesArgs() { ImmutableMap.builder() .put("key", ImmutableMap.builder().put("child", "value").build()) .build()), + Arguments.of( + ExtendedAttributes.builder().put("key", Value.of("value")).build(), + ImmutableMap.builder().put("key", Value.of("value")).build()), Arguments.of( ExtendedAttributes.builder() .put(ExtendedAttributeKey.stringKey("key"), "value") @@ -255,6 +261,11 @@ private static Stream attributesArgs() { ImmutableMap.builder() .put("key", ImmutableMap.builder().put("child", "value").build()) .build()), + Arguments.of( + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of("value")) + .build(), + ImmutableMap.builder().put("key", Value.of("value")).build()), // Multiple entries Arguments.of( ExtendedAttributes.builder() @@ -268,6 +279,7 @@ private static Stream attributesArgs() { .put("key8", 1L, 2L) .put("key9", 1.1, 2.2) .put("key10", ExtendedAttributes.builder().put("child", "value").build()) + .put("key11", Value.of("value")) .build(), ImmutableMap.builder() .put("key1", "value1") @@ -280,6 +292,7 @@ private static Stream attributesArgs() { .put("key8", Arrays.asList(1L, 2L)) .put("key9", Arrays.asList(1.1, 2.2)) .put("key10", ImmutableMap.builder().put("child", "value").build()) + .put("key11", Value.of("value")) .build())); } @@ -316,6 +329,8 @@ private static ExtendedAttributeKey getKey(String key, Object value) { return ExtendedAttributeKey.doubleArrayKey(key); case MAP: return ExtendedAttributeKey.mapKey(key); + case VALUE: + return ExtendedAttributeKey.valueKey(key); } throw new IllegalArgumentException(); } @@ -355,6 +370,9 @@ private static ExtendedAttributeType getType(Object value) { if ((value instanceof Map)) { return ExtendedAttributeType.MAP; } + if (value instanceof Value) { + return ExtendedAttributeType.VALUE; + } throw new IllegalArgumentException("Unrecognized value type: " + value); } } diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java index a99ce97d9d0..584be7a5742 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.Value; import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.Logger; @@ -105,6 +106,7 @@ private static String flipCoin() { // Extended keys ExtendedAttributeKey mapKey = ExtendedAttributeKey.mapKey("acme.map"); + ExtendedAttributeKey> valueKey = ExtendedAttributeKey.valueKey("acme.value"); @Test @SuppressLogger(ExtendedLogsBridgeApiUsageTest.class) @@ -124,6 +126,7 @@ void extendedAttributesUsage() { .put( mapKey, ExtendedAttributes.builder().put("childStr", "value").put("childLong", 1L).build()) + .put(valueKey, Value.of("value")) .build(); // Retrieval @@ -138,6 +141,7 @@ void extendedAttributesUsage() { assertThat(extendedAttributes.get(mapKey)) .isEqualTo( ExtendedAttributes.builder().put("childStr", "value").put("childLong", 1L).build()); + assertThat(extendedAttributes.get(valueKey)).isEqualTo(Value.of("value")); // Iteration // Output: @@ -148,6 +152,7 @@ void extendedAttributesUsage() { // acme.long(LONG): 1 // acme.long_array(LONG_ARRAY): [1, 2] // acme.map(MAP): {childLong=1, childStr="value"} + // acme.value(VALUE): ValueString{value} // acme.string(STRING): value // acme.string_array(STRING_ARRAY): [value1, value2] extendedAttributes.forEach( @@ -183,6 +188,7 @@ void logRecordBuilder_ExtendedAttributes() { .setAttribute( mapKey, ExtendedAttributes.builder().put("childStr", "value").put("childLong", 1L).build()) + .setAttribute(valueKey, Value.of("value")) .setAllAttributes(Attributes.builder().put("key1", "value").build()) .setAllAttributes(ExtendedAttributes.builder().put("key2", "value").build()) .emit(); @@ -228,6 +234,7 @@ void logRecordBuilder_ExtendedAttributes() { .put("childStr", "value") .put("childLong", 1L) .build()) + .put(valueKey, Value.of("value")) .put("key1", "value") .put("key2", "value") .build()); diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java index 0d2f811ee37..dc42aa627c4 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java @@ -5,6 +5,7 @@ package io.opentelemetry.exporter.internal.otlp; +import io.opentelemetry.api.common.Value; import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import io.opentelemetry.api.incubator.common.ExtendedAttributeType; import io.opentelemetry.api.incubator.common.ExtendedAttributes; @@ -174,6 +175,9 @@ public int getBinarySerializedSize( (ExtendedAttributes) value, ExtendedAttributesKeyValueListStatelessMarshaler.INSTANCE, context); + case VALUE: + return AnyValueStatelessMarshaler.INSTANCE.getBinarySerializedSize( + (Value) value, context); } // Error prone ensures the switch statement is complete, otherwise only can happen with // unaligned versions which are not supported. @@ -220,6 +224,9 @@ public void writeTo( ExtendedAttributesKeyValueListStatelessMarshaler.INSTANCE, context); return; + case VALUE: + AnyValueStatelessMarshaler.INSTANCE.writeTo(output, (Value) value, context); + return; } // Error prone ensures the switch statement is complete, otherwise only can happen with // unaligned versions which are not supported. diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java index 552fd3c7f4c..0bc9967095b 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java @@ -5,6 +5,7 @@ package io.opentelemetry.exporter.internal.otlp; +import io.opentelemetry.api.common.Value; import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.incubator.internal.InternalExtendedAttributeKeyImpl; @@ -116,6 +117,8 @@ private static KeyValueMarshaler create(ExtendedAttributeKey attributeKey, Ob new KeyValueListAnyValueMarshaler( new KeyValueListAnyValueMarshaler.KeyValueListMarshaler( createForExtendedAttributes((ExtendedAttributes) value)))); + case VALUE: + return new KeyValueMarshaler(keyUtf8, AnyValueMarshaler.create((Value) value)); } // Error prone ensures the switch statement is complete, otherwise only can happen with // unaligned versions which are not supported.