From dbf4cc75dce58e82c0ef9a2ffc742f2739ed4a30 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sat, 7 Feb 2026 09:52:54 -0800 Subject: [PATCH] Deprecate ExtendedAttributes, ExtendedAttributeKey, ExtendedAttributeType, ExtendedAttributesBuilder --- .../common/ArrayBackedExtendedAttributes.java | 1 + .../ArrayBackedExtendedAttributesBuilder.java | 26 +-- .../common/ExtendedAttributeKey.java | 2 + .../common/ExtendedAttributeType.java | 3 + .../incubator/common/ExtendedAttributes.java | 4 + .../common/ExtendedAttributesBuilder.java | 39 ++-- .../InternalExtendedAttributeKeyImpl.java | 66 +++--- .../incubator/logs/ExtendedDefaultLogger.java | 5 +- .../logs/ExtendedLogRecordBuilder.java | 46 +++-- .../common/ExtendedAttributesTest.java | 195 ++++++++++-------- .../logs/ExtendedLogsBridgeApiUsageTest.java | 17 +- ...edAttributeKeyValueStatelessMarshaler.java | 59 +++--- .../internal/otlp/IncubatingUtil.java | 23 ++- .../LogsRequestMarshalerIncubatingTest.java | 12 +- .../internal/ExtendedAttributesMap.java | 35 ++-- .../internal/ExtendedAttributesValueTest.java | 18 +- sdk/logs/build.gradle.kts | 6 + .../sdk/logs/ExtendedSdkLogRecordBuilder.java | 8 +- .../sdk/logs/ExtendedSdkLogRecordData.java | 4 +- .../logs/ExtendedSdkReadWriteLogRecord.java | 21 +- .../data/internal/ExtendedLogRecordData.java | 9 +- .../internal/ExtendedReadWriteLogRecord.java | 22 +- sdk/testing/build.gradle.kts | 9 + .../internal/TestExtendedLogRecordData.java | 9 +- 24 files changed, 377 insertions(+), 262 deletions(-) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java index fed39323f98..ec134c517c7 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java @@ -18,6 +18,7 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +@SuppressWarnings("deprecation") @Immutable final class ArrayBackedExtendedAttributes extends ImmutableKeyValuePairs, Object> implements ExtendedAttributes { diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java index ec2d4454236..312ec35266d 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java @@ -5,15 +5,6 @@ package io.opentelemetry.api.incubator.common; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey; - import io.opentelemetry.api.common.Value; import io.opentelemetry.api.common.ValueType; import java.util.ArrayList; @@ -21,6 +12,7 @@ import java.util.List; import java.util.function.Predicate; +@SuppressWarnings("deprecation") class ArrayBackedExtendedAttributesBuilder implements ExtendedAttributesBuilder { private final List data; @@ -62,16 +54,16 @@ private void putValue(ExtendedAttributeKey key, Value valueObj) { String keyName = key.getKey(); switch (valueObj.getType()) { case STRING: - put(stringKey(keyName), ((Value) valueObj).getValue()); + put(ExtendedAttributeKey.stringKey(keyName), ((Value) valueObj).getValue()); return; case LONG: - put(longKey(keyName), ((Value) valueObj).getValue()); + put(ExtendedAttributeKey.longKey(keyName), ((Value) valueObj).getValue()); return; case DOUBLE: - put(doubleKey(keyName), ((Value) valueObj).getValue()); + put(ExtendedAttributeKey.doubleKey(keyName), ((Value) valueObj).getValue()); return; case BOOLEAN: - put(booleanKey(keyName), ((Value) valueObj).getValue()); + put(ExtendedAttributeKey.booleanKey(keyName), ((Value) valueObj).getValue()); return; case ARRAY: List> arrayValues = (List>) valueObj.getValue(); @@ -82,28 +74,28 @@ private void putValue(ExtendedAttributeKey key, Value valueObj) { for (Value v : arrayValues) { strings.add((String) v.getValue()); } - put(stringArrayKey(keyName), strings); + put(ExtendedAttributeKey.stringArrayKey(keyName), strings); return; case LONG_ARRAY: List longs = new ArrayList<>(arrayValues.size()); for (Value v : arrayValues) { longs.add((Long) v.getValue()); } - put(longArrayKey(keyName), longs); + put(ExtendedAttributeKey.longArrayKey(keyName), longs); return; case DOUBLE_ARRAY: List doubles = new ArrayList<>(arrayValues.size()); for (Value v : arrayValues) { doubles.add((Double) v.getValue()); } - put(doubleArrayKey(keyName), doubles); + put(ExtendedAttributeKey.doubleArrayKey(keyName), doubles); return; case BOOLEAN_ARRAY: List booleans = new ArrayList<>(arrayValues.size()); for (Value v : arrayValues) { booleans.add((Boolean) v.getValue()); } - put(booleanArrayKey(keyName), booleans); + put(ExtendedAttributeKey.booleanArrayKey(keyName), booleans); return; case VALUE: // Not coercible (empty, non-homogeneous, or unsupported element type) 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 4f48dbd8973..89a90efe8c6 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 @@ -30,7 +30,9 @@ * * * @param The type of value that can be set with the key. + * @deprecated Use {@link AttributeKey} with {@link AttributeKey#valueKey(String)} instead. */ +@Deprecated @Immutable public interface ExtendedAttributeKey { /** Returns the underlying String representation of the key. */ 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 26e655e9ab2..e032e659a31 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 @@ -10,7 +10,10 @@ * hence the types of values that are allowed for {@link ExtendedAttributes}. * *

This is a superset of {@link io.opentelemetry.api.common.AttributeType}, + * + * @deprecated Use {@link io.opentelemetry.api.common.AttributeType} instead. */ +@Deprecated public enum ExtendedAttributeType { // Types copied AttributeType STRING, 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 14a16778d3d..5fe75be4cb5 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 @@ -47,7 +47,11 @@ * {@link ExtendedAttributes} *

  • {@link #get(AttributeKey)} supports reading values using standard {@link AttributeKey} * + * + * @deprecated Use {@link Attributes} with {@link + * io.opentelemetry.api.common.AttributeKey#valueKey(String)} instead. */ +@Deprecated @Immutable public interface ExtendedAttributes { 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 0f4b9c942e2..a8f7fdf72a4 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 @@ -5,16 +5,6 @@ package io.opentelemetry.api.incubator.common; -import static io.opentelemetry.api.incubator.common.ArrayBackedExtendedAttributesBuilder.toList; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey; - import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; @@ -22,7 +12,13 @@ import java.util.List; import java.util.function.Predicate; -/** A builder of {@link ExtendedAttributes} supporting an arbitrary number of key-value pairs. */ +/** + * A builder of {@link ExtendedAttributes} supporting an arbitrary number of key-value pairs. + * + * @deprecated Use {@link io.opentelemetry.api.common.AttributesBuilder} with {@link + * io.opentelemetry.api.common.AttributeKey#valueKey(String)} instead. + */ +@Deprecated public interface ExtendedAttributesBuilder { /** Create the {@link ExtendedAttributes} from this. */ ExtendedAttributes build(); @@ -85,7 +81,7 @@ default ExtendedAttributesBuilder put(AttributeKey key, T value) { * @return this Builder */ default ExtendedAttributesBuilder put(String key, String value) { - return put(stringKey(key), value); + return put(ExtendedAttributeKey.stringKey(key), value); } /** @@ -97,7 +93,7 @@ default ExtendedAttributesBuilder put(String key, String value) { * @return this Builder */ default ExtendedAttributesBuilder put(String key, long value) { - return put(longKey(key), value); + return put(ExtendedAttributeKey.longKey(key), value); } /** @@ -109,7 +105,7 @@ default ExtendedAttributesBuilder put(String key, long value) { * @return this Builder */ default ExtendedAttributesBuilder put(String key, double value) { - return put(doubleKey(key), value); + return put(ExtendedAttributeKey.doubleKey(key), value); } /** @@ -121,7 +117,7 @@ default ExtendedAttributesBuilder put(String key, double value) { * @return this Builder */ default ExtendedAttributesBuilder put(String key, boolean value) { - return put(booleanKey(key), value); + return put(ExtendedAttributeKey.booleanKey(key), value); } /** @@ -151,7 +147,7 @@ default ExtendedAttributesBuilder put(String key, String... value) { if (value == null) { return this; } - return put(stringArrayKey(key), Arrays.asList(value)); + return put(ExtendedAttributeKey.stringArrayKey(key), Arrays.asList(value)); } /** @@ -179,7 +175,8 @@ default ExtendedAttributesBuilder put(String key, long... value) { if (value == null) { return this; } - return put(longArrayKey(key), toList(value)); + return put( + ExtendedAttributeKey.longArrayKey(key), ArrayBackedExtendedAttributesBuilder.toList(value)); } /** @@ -194,7 +191,9 @@ default ExtendedAttributesBuilder put(String key, double... value) { if (value == null) { return this; } - return put(doubleArrayKey(key), toList(value)); + return put( + ExtendedAttributeKey.doubleArrayKey(key), + ArrayBackedExtendedAttributesBuilder.toList(value)); } /** @@ -209,7 +208,9 @@ default ExtendedAttributesBuilder put(String key, boolean... value) { if (value == null) { return this; } - return put(booleanArrayKey(key), toList(value)); + return put( + ExtendedAttributeKey.booleanArrayKey(key), + ArrayBackedExtendedAttributesBuilder.toList(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 834c9653f39..1ab91765a35 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 @@ -7,8 +7,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeType; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributeType; import io.opentelemetry.api.internal.InternalAttributeKeyImpl; import java.nio.charset.StandardCharsets; import javax.annotation.Nullable; @@ -17,16 +15,19 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class InternalExtendedAttributeKeyImpl implements ExtendedAttributeKey { +@SuppressWarnings("deprecation") +public final class InternalExtendedAttributeKeyImpl + implements io.opentelemetry.api.incubator.common.ExtendedAttributeKey { - private final ExtendedAttributeType type; + private final io.opentelemetry.api.incubator.common.ExtendedAttributeType type; private final String key; private final int hashCode; @Nullable private byte[] keyUtf8; @Nullable private AttributeKey attributeKey; - private InternalExtendedAttributeKeyImpl(ExtendedAttributeType type, String key) { + private InternalExtendedAttributeKeyImpl( + io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) { if (type == null) { throw new NullPointerException("Null type"); } @@ -38,13 +39,13 @@ private InternalExtendedAttributeKeyImpl(ExtendedAttributeType type, String key) this.hashCode = buildHashCode(type, key); } - public static ExtendedAttributeKey create( - @Nullable String key, ExtendedAttributeType type) { + public static io.opentelemetry.api.incubator.common.ExtendedAttributeKey create( + @Nullable String key, io.opentelemetry.api.incubator.common.ExtendedAttributeType type) { return new InternalExtendedAttributeKeyImpl<>(type, key != null ? key : ""); } @Override - public ExtendedAttributeType getType() { + public io.opentelemetry.api.incubator.common.ExtendedAttributeType getType() { return type; } @@ -100,7 +101,8 @@ private int buildHashCode() { return buildHashCode(type, key); } - private static int buildHashCode(ExtendedAttributeType type, String key) { + private static int buildHashCode( + io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) { int result = 1; result *= 1000003; result ^= type.hashCode(); @@ -110,13 +112,13 @@ private static int buildHashCode(ExtendedAttributeType type, String key) { } /** - * Return the equivalent {@link AttributeKey} for the {@link ExtendedAttributeKey}, or {@code - * null} if the {@link #getType()} has no equivalent {@link - * io.opentelemetry.api.common.AttributeType}. + * Return the equivalent {@link AttributeKey} for the {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}, or {@code null} if the {@link + * #getType()} has no equivalent {@link io.opentelemetry.api.common.AttributeType}. */ @Nullable - @SuppressWarnings("deprecation") // Supporting deprecated EXTENDED_ATTRIBUTES until removed - public static AttributeKey toAttributeKey(ExtendedAttributeKey extendedAttributeKey) { + public static AttributeKey toAttributeKey( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey extendedAttributeKey) { switch (extendedAttributeKey.getType()) { case STRING: return InternalAttributeKeyImpl.create(extendedAttributeKey.getKey(), AttributeType.STRING); @@ -148,36 +150,50 @@ public static AttributeKey toAttributeKey(ExtendedAttributeKey extende "Unrecognized extendedAttributeKey type: " + extendedAttributeKey.getType()); } - /** Return the equivalent {@link ExtendedAttributeKey} for the {@link AttributeKey}. */ - public static ExtendedAttributeKey toExtendedAttributeKey(AttributeKey attributeKey) { + /** + * Return the equivalent {@link io.opentelemetry.api.incubator.common.ExtendedAttributeKey} for + * the {@link AttributeKey}. + */ + public static + io.opentelemetry.api.incubator.common.ExtendedAttributeKey toExtendedAttributeKey( + AttributeKey attributeKey) { switch (attributeKey.getType()) { case STRING: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.STRING); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING); case BOOLEAN: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.BOOLEAN); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN); case LONG: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.LONG); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG); case DOUBLE: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.DOUBLE); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE); case STRING_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.STRING_ARRAY); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING_ARRAY); case BOOLEAN_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.BOOLEAN_ARRAY); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN_ARRAY); case LONG_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.LONG_ARRAY); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG_ARRAY); case DOUBLE_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.DOUBLE_ARRAY); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE_ARRAY); case VALUE: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.VALUE); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.VALUE); } throw new IllegalArgumentException("Unrecognized attributeKey type: " + attributeKey.getType()); } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java index 14731495606..0984d9bcd60 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java @@ -7,7 +7,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import io.opentelemetry.api.logs.Logger; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.context.Context; @@ -15,6 +14,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; +@SuppressWarnings("deprecation") class ExtendedDefaultLogger implements ExtendedLogger { private static final Logger INSTANCE = new ExtendedDefaultLogger(); @@ -52,7 +52,8 @@ public ExtendedLogRecordBuilder setException(Throwable throwable) { } @Override - public ExtendedLogRecordBuilder setAttribute(ExtendedAttributeKey key, T value) { + public ExtendedLogRecordBuilder setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value) { return this; } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java index de25aabe4d4..3dd6dd0b7c3 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java @@ -8,8 +8,6 @@ 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.LogRecordBuilder; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.context.Context; @@ -18,6 +16,7 @@ import javax.annotation.Nullable; /** Extended {@link LogRecordBuilder} with experimental APIs. */ +@SuppressWarnings("deprecation") public interface ExtendedLogRecordBuilder extends LogRecordBuilder { // keep this class even if it is empty, since experimental methods may be added in the future. @@ -74,10 +73,10 @@ default ExtendedLogRecordBuilder setBody(Value body) { * {@inheritDoc} * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be - * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted - * log record, there is no difference between adding attributes using the standard or extended - * attribute APIs. + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as + * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there + * is no difference between adding attributes using the standard or extended attribute APIs. */ @SuppressWarnings("unchecked") @Override @@ -95,18 +94,22 @@ default ExtendedLogRecordBuilder setAllAttributes(Attributes attributes) { * keys, the old values are replaced by the specified values. * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be - * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted - * log record, there is no difference between adding attributes using the standard or extended - * attribute APIs. + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as + * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there + * is no difference between adding attributes using the standard or extended attribute APIs. */ @SuppressWarnings("unchecked") - default ExtendedLogRecordBuilder setAllAttributes(ExtendedAttributes attributes) { + default ExtendedLogRecordBuilder setAllAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes) { if (attributes == null || attributes.isEmpty()) { return this; } attributes.forEach( - (attributeKey, value) -> setAttribute((ExtendedAttributeKey) attributeKey, value)); + (attributeKey, value) -> + setAttribute( + (io.opentelemetry.api.incubator.common.ExtendedAttributeKey) attributeKey, + value)); return this; } @@ -114,10 +117,10 @@ default ExtendedLogRecordBuilder setAllAttributes(ExtendedAttributes attributes) * {@inheritDoc} * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be - * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted - * log record, there is no difference between adding attributes using the standard or extended - * attribute APIs. + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as + * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there + * is no difference between adding attributes using the standard or extended attribute APIs. */ @Override ExtendedLogRecordBuilder setAttribute(AttributeKey key, @Nullable T value); @@ -126,12 +129,13 @@ default ExtendedLogRecordBuilder setAllAttributes(ExtendedAttributes attributes) * Set an attribute. * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be - * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted - * log record, there is no difference between adding attributes using the standard or extended - * attribute APIs. + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as + * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there + * is no difference between adding attributes using the standard or extended attribute APIs. */ - ExtendedLogRecordBuilder setAttribute(ExtendedAttributeKey key, T value); + ExtendedLogRecordBuilder setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value); /** Set standard {@code exception.*} attributes based on the {@code throwable}. */ ExtendedLogRecordBuilder setException(Throwable throwable); 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 2d94aca5556..ee649872527 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 @@ -5,15 +5,6 @@ package io.opentelemetry.api.incubator.common; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -229,7 +220,9 @@ private static Stream attributesArgs() { .put("key", ImmutableMap.builder().put("child", "value").build()) .build()), Arguments.of( - ExtendedAttributes.builder().put(valueKey("key"), Value.of("value")).build(), + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of("value")) + .build(), ImmutableMap.builder().put("key", "value").build()), Arguments.of( ExtendedAttributes.builder() @@ -292,7 +285,7 @@ private static Stream attributesArgs() { .put("key8", 1L, 2L) .put("key9", 1.1, 2.2) .put("key10", ExtendedAttributes.builder().put("child", "value").build()) - .put(valueKey("key11"), Value.of("value")) + .put(ExtendedAttributeKey.valueKey("key11"), Value.of("value")) .build(), ImmutableMap.builder() .put("key1", "value1") @@ -393,76 +386,88 @@ private static ExtendedAttributeType getType(Object value) { void complexValueStoredAsString() { // When putting a VALUE attribute with a string Value, it should be stored as STRING type ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), Value.of("test")).build(); + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of("test")) + .build(); // Should be stored as STRING type internally - assertThat(attributes.get(stringKey("key"))).isEqualTo("test"); - assertThat(attributes.get(valueKey("key"))).isEqualTo(Value.of("test")); + assertThat(attributes.get(ExtendedAttributeKey.stringKey("key"))).isEqualTo("test"); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(Value.of("test")); // forEach should show STRING type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(stringKey("key"), "test")); + assertThat(entriesSeen).containsExactly(entry(ExtendedAttributeKey.stringKey("key"), "test")); // asMap should show STRING type - assertThat(attributes.asMap()).containsExactly(entry(stringKey("key"), "test")); + assertThat(attributes.asMap()) + .containsExactly(entry(ExtendedAttributeKey.stringKey("key"), "test")); } @Test void complexValueStoredAsLong() { // When putting a VALUE attribute with a long Value, it should be stored as LONG type ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), Value.of(123L)).build(); + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of(123L)) + .build(); // Should be stored as LONG type internally - assertThat(attributes.get(longKey("key"))).isEqualTo(123L); - assertThat(attributes.get(valueKey("key"))).isEqualTo(Value.of(123L)); + assertThat(attributes.get(ExtendedAttributeKey.longKey("key"))).isEqualTo(123L); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(Value.of(123L)); // forEach should show LONG type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(longKey("key"), 123L)); + assertThat(entriesSeen).containsExactly(entry(ExtendedAttributeKey.longKey("key"), 123L)); // asMap should show LONG type - assertThat(attributes.asMap()).containsExactly(entry(longKey("key"), 123L)); + assertThat(attributes.asMap()) + .containsExactly(entry(ExtendedAttributeKey.longKey("key"), 123L)); } @Test void complexValueStoredAsDouble() { // When putting a VALUE attribute with a double Value, it should be stored as DOUBLE type ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), Value.of(1.23)).build(); + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of(1.23)) + .build(); // Should be stored as DOUBLE type internally - assertThat(attributes.get(doubleKey("key"))).isEqualTo(1.23); - assertThat(attributes.get(valueKey("key"))).isEqualTo(Value.of(1.23)); + assertThat(attributes.get(ExtendedAttributeKey.doubleKey("key"))).isEqualTo(1.23); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(Value.of(1.23)); // forEach should show DOUBLE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(doubleKey("key"), 1.23)); + assertThat(entriesSeen).containsExactly(entry(ExtendedAttributeKey.doubleKey("key"), 1.23)); // asMap should show DOUBLE type - assertThat(attributes.asMap()).containsExactly(entry(doubleKey("key"), 1.23)); + assertThat(attributes.asMap()) + .containsExactly(entry(ExtendedAttributeKey.doubleKey("key"), 1.23)); } @Test void complexValueStoredAsBoolean() { // When putting a VALUE attribute with a boolean Value, it should be stored as BOOLEAN type ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), Value.of(true)).build(); + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of(true)) + .build(); // Should be stored as BOOLEAN type internally - assertThat(attributes.get(booleanKey("key"))).isEqualTo(true); - assertThat(attributes.get(valueKey("key"))).isEqualTo(Value.of(true)); + assertThat(attributes.get(ExtendedAttributeKey.booleanKey("key"))).isEqualTo(true); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(Value.of(true)); // forEach should show BOOLEAN type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(booleanKey("key"), true)); + assertThat(entriesSeen).containsExactly(entry(ExtendedAttributeKey.booleanKey("key"), true)); // asMap should show BOOLEAN type - assertThat(attributes.asMap()).containsExactly(entry(booleanKey("key"), true)); + assertThat(attributes.asMap()) + .containsExactly(entry(ExtendedAttributeKey.booleanKey("key"), true)); } @Test @@ -471,22 +476,28 @@ void complexValueStoredAsStringArray() { // STRING_ARRAY type ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Arrays.asList(Value.of("a"), Value.of("b")))) + .put( + ExtendedAttributeKey.valueKey("key"), + Value.of(Arrays.asList(Value.of("a"), Value.of("b")))) .build(); // Should be stored as STRING_ARRAY type internally - assertThat(attributes.get(stringArrayKey("key"))).containsExactly("a", "b"); - assertThat(attributes.get(valueKey("key"))) + assertThat(attributes.get(ExtendedAttributeKey.stringArrayKey("key"))) + .containsExactly("a", "b"); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))) .isEqualTo(Value.of(Arrays.asList(Value.of("a"), Value.of("b")))); // forEach should show STRING_ARRAY type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(stringArrayKey("key"), Arrays.asList("a", "b"))); + assertThat(entriesSeen) + .containsExactly( + entry(ExtendedAttributeKey.stringArrayKey("key"), Arrays.asList("a", "b"))); // asMap should show STRING_ARRAY type assertThat(attributes.asMap()) - .containsExactly(entry(stringArrayKey("key"), Arrays.asList("a", "b"))); + .containsExactly( + entry(ExtendedAttributeKey.stringArrayKey("key"), Arrays.asList("a", "b"))); } @Test @@ -495,22 +506,25 @@ void complexValueStoredAsLongArray() { // LONG_ARRAY type ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Arrays.asList(Value.of(1L), Value.of(2L)))) + .put( + ExtendedAttributeKey.valueKey("key"), + Value.of(Arrays.asList(Value.of(1L), Value.of(2L)))) .build(); // Should be stored as LONG_ARRAY type internally - assertThat(attributes.get(longArrayKey("key"))).containsExactly(1L, 2L); - assertThat(attributes.get(valueKey("key"))) + assertThat(attributes.get(ExtendedAttributeKey.longArrayKey("key"))).containsExactly(1L, 2L); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))) .isEqualTo(Value.of(Arrays.asList(Value.of(1L), Value.of(2L)))); // forEach should show LONG_ARRAY type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(longArrayKey("key"), Arrays.asList(1L, 2L))); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.longArrayKey("key"), Arrays.asList(1L, 2L))); // asMap should show LONG_ARRAY type assertThat(attributes.asMap()) - .containsExactly(entry(longArrayKey("key"), Arrays.asList(1L, 2L))); + .containsExactly(entry(ExtendedAttributeKey.longArrayKey("key"), Arrays.asList(1L, 2L))); } @Test @@ -519,22 +533,28 @@ void complexValueStoredAsDoubleArray() { // DOUBLE_ARRAY type ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Arrays.asList(Value.of(1.1), Value.of(2.2)))) + .put( + ExtendedAttributeKey.valueKey("key"), + Value.of(Arrays.asList(Value.of(1.1), Value.of(2.2)))) .build(); // Should be stored as DOUBLE_ARRAY type internally - assertThat(attributes.get(doubleArrayKey("key"))).containsExactly(1.1, 2.2); - assertThat(attributes.get(valueKey("key"))) + assertThat(attributes.get(ExtendedAttributeKey.doubleArrayKey("key"))) + .containsExactly(1.1, 2.2); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))) .isEqualTo(Value.of(Arrays.asList(Value.of(1.1), Value.of(2.2)))); // forEach should show DOUBLE_ARRAY type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(doubleArrayKey("key"), Arrays.asList(1.1, 2.2))); + assertThat(entriesSeen) + .containsExactly( + entry(ExtendedAttributeKey.doubleArrayKey("key"), Arrays.asList(1.1, 2.2))); // asMap should show DOUBLE_ARRAY type assertThat(attributes.asMap()) - .containsExactly(entry(doubleArrayKey("key"), Arrays.asList(1.1, 2.2))); + .containsExactly( + entry(ExtendedAttributeKey.doubleArrayKey("key"), Arrays.asList(1.1, 2.2))); } @Test @@ -543,23 +563,28 @@ void complexValueStoredAsBooleanArray() { // BOOLEAN_ARRAY type ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Arrays.asList(Value.of(true), Value.of(false)))) + .put( + ExtendedAttributeKey.valueKey("key"), + Value.of(Arrays.asList(Value.of(true), Value.of(false)))) .build(); // Should be stored as BOOLEAN_ARRAY type internally - assertThat(attributes.get(booleanArrayKey("key"))).containsExactly(true, false); - assertThat(attributes.get(valueKey("key"))) + assertThat(attributes.get(ExtendedAttributeKey.booleanArrayKey("key"))) + .containsExactly(true, false); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))) .isEqualTo(Value.of(Arrays.asList(Value.of(true), Value.of(false)))); // forEach should show BOOLEAN_ARRAY type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); assertThat(entriesSeen) - .containsExactly(entry(booleanArrayKey("key"), Arrays.asList(true, false))); + .containsExactly( + entry(ExtendedAttributeKey.booleanArrayKey("key"), Arrays.asList(true, false))); // asMap should show BOOLEAN_ARRAY type assertThat(attributes.asMap()) - .containsExactly(entry(booleanArrayKey("key"), Arrays.asList(true, false))); + .containsExactly( + entry(ExtendedAttributeKey.booleanArrayKey("key"), Arrays.asList(true, false))); } @Test @@ -575,17 +600,17 @@ void simpleAttributeRetrievedAsComplexValue() { .put("doubleArray", 1.1, 2.2) .put("booleanArray", true, false) .build(); - assertThat(attributes.get(valueKey("string"))).isEqualTo(Value.of("test")); - assertThat(attributes.get(valueKey("long"))).isEqualTo(Value.of(123L)); - assertThat(attributes.get(valueKey("double"))).isEqualTo(Value.of(1.23)); - assertThat(attributes.get(valueKey("boolean"))).isEqualTo(Value.of(true)); - assertThat(attributes.get(valueKey("stringArray"))) + assertThat(attributes.get(ExtendedAttributeKey.valueKey("string"))).isEqualTo(Value.of("test")); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("long"))).isEqualTo(Value.of(123L)); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("double"))).isEqualTo(Value.of(1.23)); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("boolean"))).isEqualTo(Value.of(true)); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("stringArray"))) .isEqualTo(Value.of(Arrays.asList(Value.of("a"), Value.of("b")))); - assertThat(attributes.get(valueKey("longArray"))) + assertThat(attributes.get(ExtendedAttributeKey.valueKey("longArray"))) .isEqualTo(Value.of(Arrays.asList(Value.of(1L), Value.of(2L)))); - assertThat(attributes.get(valueKey("doubleArray"))) + assertThat(attributes.get(ExtendedAttributeKey.valueKey("doubleArray"))) .isEqualTo(Value.of(Arrays.asList(Value.of(1.1), Value.of(2.2)))); - assertThat(attributes.get(valueKey("booleanArray"))) + assertThat(attributes.get(ExtendedAttributeKey.valueKey("booleanArray"))) .isEqualTo(Value.of(Arrays.asList(Value.of(true), Value.of(false)))); } @@ -593,12 +618,12 @@ void simpleAttributeRetrievedAsComplexValue() { void emptyValueArrayRetrievedAsAnyArrayType() { ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Collections.emptyList())) + .put(ExtendedAttributeKey.valueKey("key"), Value.of(Collections.emptyList())) .build(); - assertThat(attributes.get(stringArrayKey("key"))).isEmpty(); - assertThat(attributes.get(longArrayKey("key"))).isEmpty(); - assertThat(attributes.get(doubleArrayKey("key"))).isEmpty(); - assertThat(attributes.get(booleanArrayKey("key"))).isEmpty(); + assertThat(attributes.get(ExtendedAttributeKey.stringArrayKey("key"))).isEmpty(); + assertThat(attributes.get(ExtendedAttributeKey.longArrayKey("key"))).isEmpty(); + assertThat(attributes.get(ExtendedAttributeKey.doubleArrayKey("key"))).isEmpty(); + assertThat(attributes.get(ExtendedAttributeKey.booleanArrayKey("key"))).isEmpty(); } @Test @@ -617,14 +642,14 @@ void putNullKey() { @Test void putNullValue() { ExtendedAttributes attributes = - ExtendedAttributes.builder().put(stringKey("key"), null).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.stringKey("key"), null).build(); assertThat(attributes.isEmpty()).isTrue(); } @Test void putEmptyKey() { ExtendedAttributes attributes = - ExtendedAttributes.builder().put(stringKey(""), "value").build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.stringKey(""), "value").build(); assertThat(attributes.isEmpty()).isTrue(); } @@ -637,7 +662,7 @@ void extendedAttributesNotConvertibleToValue() { .build(); // Getting as VALUE should return null since EXTENDED_ATTRIBUTES cannot be converted to Value - assertThat(attributes.get(valueKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isNull(); } @Test @@ -645,15 +670,16 @@ void complexValueWithKeyValueList() { // KEY_VALUE_LIST should be kept as VALUE type Value kvListValue = Value.of(Collections.emptyMap()); ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), kvListValue).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.valueKey("key"), kvListValue).build(); // Should be stored as VALUE type - assertThat(attributes.get(valueKey("key"))).isEqualTo(kvListValue); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(kvListValue); // forEach should show VALUE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(valueKey("key"), kvListValue)); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.valueKey("key"), kvListValue)); } @Test @@ -661,15 +687,16 @@ void complexValueWithBytes() { // BYTES should be kept as VALUE type Value bytesValue = Value.of(new byte[] {1, 2, 3}); ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), bytesValue).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.valueKey("key"), bytesValue).build(); // Should be stored as VALUE type - assertThat(attributes.get(valueKey("key"))).isEqualTo(bytesValue); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(bytesValue); // forEach should show VALUE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(valueKey("key"), bytesValue)); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.valueKey("key"), bytesValue)); } @Test @@ -677,15 +704,16 @@ void complexValueWithNonHomogeneousArray() { // Non-homogeneous array should be kept as VALUE type Value mixedArray = Value.of(Arrays.asList(Value.of("string"), Value.of(123L))); ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), mixedArray).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.valueKey("key"), mixedArray).build(); // Should be stored as VALUE type - assertThat(attributes.get(valueKey("key"))).isEqualTo(mixedArray); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(mixedArray); // forEach should show VALUE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(valueKey("key"), mixedArray)); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.valueKey("key"), mixedArray)); } @Test @@ -697,15 +725,16 @@ void complexValueWithNestedArray() { Value.of(Arrays.asList(Value.of("a"), Value.of("b"))), Value.of(Arrays.asList(Value.of("c"), Value.of("d"))))); ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), nestedArray).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.valueKey("key"), nestedArray).build(); // Should be stored as VALUE type - assertThat(attributes.get(valueKey("key"))).isEqualTo(nestedArray); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(nestedArray); // forEach should show VALUE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(valueKey("key"), nestedArray)); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.valueKey("key"), nestedArray)); } @Test @@ -714,9 +743,9 @@ void getNonExistentArrayType() { ExtendedAttributes attributes = ExtendedAttributes.builder().put("key", "value").build(); // Looking for an array type when only a string exists should return null - assertThat(attributes.get(stringArrayKey("key"))).isNull(); - assertThat(attributes.get(longArrayKey("key"))).isNull(); - assertThat(attributes.get(doubleArrayKey("key"))).isNull(); - assertThat(attributes.get(booleanArrayKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.stringArrayKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.longArrayKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.doubleArrayKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.booleanArrayKey("key"))).isNull(); } } 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 b451bbf5dba..0e82953e929 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 @@ -13,8 +13,6 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.KeyValue; 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; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; @@ -31,6 +29,7 @@ import org.junit.jupiter.api.Test; /** Demonstrating usage of extended Logs Bridge API. */ +@SuppressWarnings("deprecation") class ExtendedLogsBridgeApiUsageTest { private static final java.util.logging.Logger logger = @@ -106,15 +105,16 @@ private static String flipCoin() { AttributeKey> doubleArrKey = AttributeKey.doubleArrayKey("acme.double_array"); // VALUE key - ExtendedAttributeKey> valueKey = ExtendedAttributeKey.valueKey("acme.value"); + io.opentelemetry.api.incubator.common.ExtendedAttributeKey> valueKey = + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("acme.value"); @Test @SuppressLogger(ExtendedLogsBridgeApiUsageTest.class) void extendedAttributesUsage() { // Initialize from builder. Varargs style initialization (ExtendedAttributes.of(...) not // supported. - ExtendedAttributes extendedAttributes = - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes extendedAttributes = + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() .put(strKey, "value") .put(longKey, 1L) .put(booleanKey, true) @@ -191,7 +191,10 @@ void logRecordBuilder_ExtendedAttributes() { Value.of( KeyValue.of("childStr", Value.of("value")), KeyValue.of("childLong", Value.of(1L)))) .setAllAttributes(Attributes.builder().put("key1", "value").build()) - .setAllAttributes(ExtendedAttributes.builder().put("key2", "value").build()) + .setAllAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() + .put("key2", "value") + .build()) .emit(); assertThat(exporter.getFinishedLogRecordItems()) @@ -225,7 +228,7 @@ void logRecordBuilder_ExtendedAttributes() { // But preferably access and serialize full extended attributes assertThat(extendedLogRecordData.getExtendedAttributes()) .isEqualTo( - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() .put(strKey, "value") .put(longKey, 1L) .put(booleanKey, true) 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 b812a9d2a29..06c2918faf6 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 @@ -6,9 +6,6 @@ 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; import io.opentelemetry.api.incubator.internal.InternalExtendedAttributeKeyImpl; import io.opentelemetry.exporter.internal.marshal.CodedOutputStream; import io.opentelemetry.exporter.internal.marshal.MarshalerContext; @@ -27,13 +24,16 @@ import java.util.Objects; /** - * A Marshaler of {@link ExtendedAttributes} key value pairs. See {@link KeyValueMarshaler}. + * A Marshaler of {@link io.opentelemetry.api.incubator.common.ExtendedAttributes} key value pairs. + * See {@link KeyValueMarshaler}. * *

    This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ +@SuppressWarnings("deprecation") public final class ExtendedAttributeKeyValueStatelessMarshaler - implements StatelessMarshaler2, Object> { + implements StatelessMarshaler2< + io.opentelemetry.api.incubator.common.ExtendedAttributeKey, Object> { private static final ExtendedAttributeKeyValueStatelessMarshaler INSTANCE = new ExtendedAttributeKeyValueStatelessMarshaler(); private static final byte[] EMPTY_BYTES = new byte[0]; @@ -43,12 +43,12 @@ private ExtendedAttributeKeyValueStatelessMarshaler() {} /** * Serializes the {@code attributes}. This method reads elements from context, use together with * {@link ExtendedAttributeKeyValueStatelessMarshaler#sizeExtendedAttributes(ProtoFieldInfo, - * ExtendedAttributes, MarshalerContext)}. + * io.opentelemetry.api.incubator.common.ExtendedAttributes, MarshalerContext)}. */ public static void serializeExtendedAttributes( Serializer output, ProtoFieldInfo field, - ExtendedAttributes attributes, + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes, MarshalerContext context) throws IOException { output.writeStartRepeated(field); @@ -76,10 +76,12 @@ public static void serializeExtendedAttributes( /** * Sizes the {@code attributes}. This method adds elements to context, use together with {@link * ExtendedAttributeKeyValueStatelessMarshaler#serializeExtendedAttributes(Serializer, - * ProtoFieldInfo, ExtendedAttributes, MarshalerContext)}. + * ProtoFieldInfo, io.opentelemetry.api.incubator.common.ExtendedAttributes, MarshalerContext)}. */ public static int sizeExtendedAttributes( - ProtoFieldInfo field, ExtendedAttributes attributes, MarshalerContext context) { + ProtoFieldInfo field, + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes, + MarshalerContext context) { if (attributes.isEmpty()) { return 0; } @@ -101,7 +103,7 @@ public static int sizeExtendedAttributes( @Override public void writeTo( Serializer output, - ExtendedAttributeKey attributeKey, + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) throws IOException { @@ -119,7 +121,9 @@ public void writeTo( @Override public int getBinarySerializedSize( - ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) { + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, + Object value, + MarshalerContext context) { int size = 0; if (!attributeKey.getKey().isEmpty()) { if (attributeKey instanceof InternalExtendedAttributeKeyImpl) { @@ -138,15 +142,19 @@ public int getBinarySerializedSize( } private static class ValueStatelessMarshaler - implements StatelessMarshaler2, Object> { + implements StatelessMarshaler2< + io.opentelemetry.api.incubator.common.ExtendedAttributeKey, Object> { static final ValueStatelessMarshaler INSTANCE = new ValueStatelessMarshaler(); // Supporting deprecated EXTENDED_ATTRIBUTES type until removed - @SuppressWarnings({"unchecked", "deprecation"}) + @SuppressWarnings("unchecked") @Override public int getBinarySerializedSize( - ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) { - ExtendedAttributeType attributeType = attributeKey.getType(); + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, + Object value, + MarshalerContext context) { + io.opentelemetry.api.incubator.common.ExtendedAttributeType attributeType = + attributeKey.getType(); switch (attributeType) { case STRING: return StringAnyValueStatelessMarshaler.INSTANCE.getBinarySerializedSize( @@ -173,7 +181,7 @@ public int getBinarySerializedSize( case EXTENDED_ATTRIBUTES: return StatelessMarshalerUtil.sizeMessageWithContext( AnyValue.KVLIST_VALUE, - (ExtendedAttributes) value, + (io.opentelemetry.api.incubator.common.ExtendedAttributes) value, ExtendedAttributesKeyValueListStatelessMarshaler.INSTANCE, context); case VALUE: @@ -186,15 +194,16 @@ public int getBinarySerializedSize( } // Supporting deprecated EXTENDED_ATTRIBUTES type until removed - @SuppressWarnings({"unchecked", "deprecation"}) + @SuppressWarnings("unchecked") @Override public void writeTo( Serializer output, - ExtendedAttributeKey attributeKey, + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) throws IOException { - ExtendedAttributeType attributeType = attributeKey.getType(); + io.opentelemetry.api.incubator.common.ExtendedAttributeType attributeType = + attributeKey.getType(); switch (attributeType) { case STRING: StringAnyValueStatelessMarshaler.INSTANCE.writeTo(output, (String) value, context); @@ -222,7 +231,7 @@ public void writeTo( case EXTENDED_ATTRIBUTES: output.serializeMessageWithContext( AnyValue.KVLIST_VALUE, - (ExtendedAttributes) value, + (io.opentelemetry.api.incubator.common.ExtendedAttributes) value, ExtendedAttributesKeyValueListStatelessMarshaler.INSTANCE, context); return; @@ -237,20 +246,24 @@ public void writeTo( } private static class ExtendedAttributesKeyValueListStatelessMarshaler - implements StatelessMarshaler { + implements StatelessMarshaler { private static final ExtendedAttributesKeyValueListStatelessMarshaler INSTANCE = new ExtendedAttributesKeyValueListStatelessMarshaler(); private ExtendedAttributesKeyValueListStatelessMarshaler() {} @Override - public void writeTo(Serializer output, ExtendedAttributes value, MarshalerContext context) + public void writeTo( + Serializer output, + io.opentelemetry.api.incubator.common.ExtendedAttributes value, + MarshalerContext context) throws IOException { serializeExtendedAttributes(output, KeyValueList.VALUES, value, context); } @Override - public int getBinarySerializedSize(ExtendedAttributes value, MarshalerContext context) { + public int getBinarySerializedSize( + io.opentelemetry.api.incubator.common.ExtendedAttributes value, MarshalerContext context) { return sizeExtendedAttributes(KeyValueList.VALUES, value, context); } } 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 da34f7756cc..f4c5cf4c855 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 @@ -6,8 +6,6 @@ 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; import io.opentelemetry.exporter.internal.marshal.MarshalerContext; import io.opentelemetry.exporter.internal.marshal.Serializer; @@ -27,6 +25,7 @@ *

    This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ +@SuppressWarnings("deprecation") public class IncubatingUtil { private static final boolean INCUBATOR_AVAILABLE; @@ -62,18 +61,21 @@ public static int extendedAttributesSize(LogRecordData logRecordData) { } // TODO(jack-berg): move to KeyValueMarshaler when ExtendedAttributes is stable - private static KeyValueMarshaler[] createForExtendedAttributes(ExtendedAttributes attributes) { + private static KeyValueMarshaler[] createForExtendedAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes) { if (attributes.isEmpty()) { return EMPTY_REPEATED; } KeyValueMarshaler[] marshalers = new KeyValueMarshaler[attributes.size()]; attributes.forEach( - new BiConsumer, Object>() { + new BiConsumer, Object>() { int index = 0; @Override - public void accept(ExtendedAttributeKey attributeKey, Object o) { + public void accept( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, + Object o) { marshalers[index++] = create(attributeKey, o); } }); @@ -82,8 +84,9 @@ public void accept(ExtendedAttributeKey attributeKey, Object o) { // TODO(jack-berg): move to KeyValueMarshaler when ExtendedAttributes is stable // Supporting deprecated EXTENDED_ATTRIBUTES type until removed - @SuppressWarnings({"unchecked", "deprecation"}) - private static KeyValueMarshaler create(ExtendedAttributeKey attributeKey, Object value) { + @SuppressWarnings("unchecked") + private static KeyValueMarshaler create( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, Object value) { byte[] keyUtf8; if (attributeKey.getKey().isEmpty()) { keyUtf8 = EMPTY_BYTES; @@ -117,7 +120,8 @@ private static KeyValueMarshaler create(ExtendedAttributeKey attributeKey, Ob keyUtf8, new KeyValueListAnyValueMarshaler( new KeyValueListAnyValueMarshaler.KeyValueListMarshaler( - createForExtendedAttributes((ExtendedAttributes) value)))); + createForExtendedAttributes( + (io.opentelemetry.api.incubator.common.ExtendedAttributes) value)))); case VALUE: return new KeyValueMarshaler(keyUtf8, AnyValueMarshaler.create((Value) value)); } @@ -137,7 +141,8 @@ public static void serializeExtendedAttributes( output, LogRecord.ATTRIBUTES, getExtendedAttributes(log), context); } - private static ExtendedAttributes getExtendedAttributes(LogRecordData logRecordData) { + private static io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes( + LogRecordData logRecordData) { if (!(logRecordData instanceof ExtendedLogRecordData)) { throw new IllegalArgumentException("logRecordData must be ExtendedLogRecordData"); } diff --git a/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java b/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java index 84639db8312..56f1107e47a 100644 --- a/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java +++ b/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java @@ -14,8 +14,6 @@ import com.google.protobuf.util.JsonFormat; 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.internal.OtelEncodingUtils; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; @@ -99,7 +97,7 @@ void toProtoLogRecord(MarshalerSource marshalerSource) { // Extended fields .setEventName(EVENT_NAME) .setExtendedAttributes( - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() .put("str_key", "str_value") .put("str_arr_key", "str_value1", "str_value2") .put("bool_key", true) @@ -110,19 +108,21 @@ void toProtoLogRecord(MarshalerSource marshalerSource) { .put("int_arr_key", 1, 2) .put( "kv_list_key", - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() .put("bool_key", true) .put("double_key", 1.1) .put("int_key", 1) .put( "kv_list_key", - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes + .builder() .put("str_key", "str_value") .build()) .put("str_key", "str_value") .build()) .put( - ExtendedAttributeKey.valueKey("value_key"), + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey( + "value_key"), Value.of( io.opentelemetry.api.common.KeyValue.of( "bool_key", Value.of(true)), diff --git a/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java b/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java index 0adefdb6216..9c5ed61d3cc 100644 --- a/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java +++ b/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java @@ -6,9 +6,6 @@ package io.opentelemetry.sdk.common.internal; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; -import io.opentelemetry.api.incubator.common.ExtendedAttributesBuilder; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -19,13 +16,16 @@ * A map with a fixed capacity that drops attributes when the map gets full, and which truncates * string and array string attribute values to the {@link #lengthLimit}. * - *

    {@link ExtendedAttributes} analog of {@link AttributesMap}. + *

    {@link io.opentelemetry.api.incubator.common.ExtendedAttributes} analog of {@link + * AttributesMap}. * *

    This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ -public final class ExtendedAttributesMap extends HashMap, Object> - implements ExtendedAttributes { +@SuppressWarnings("deprecation") +public final class ExtendedAttributesMap + extends HashMap, Object> + implements io.opentelemetry.api.incubator.common.ExtendedAttributes { private static final long serialVersionUID = -2674974862318200501L; @@ -51,7 +51,8 @@ public static ExtendedAttributesMap create(long capacity, int lengthLimit) { /** Add the attribute key value pair, applying capacity and length limits. */ @Override @Nullable - public Object put(ExtendedAttributeKey key, @Nullable Object value) { + public Object put( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, @Nullable Object value) { if (value == null) { return null; } @@ -62,7 +63,8 @@ public Object put(ExtendedAttributeKey key, @Nullable Object value) { return super.put(key, AttributeUtil.applyAttributeLengthLimit(value, lengthLimit)); } - public void putIfCapacity(ExtendedAttributeKey key, @Nullable T value) { + public void putIfCapacity( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, @Nullable T value) { put(key, value); } @@ -76,12 +78,12 @@ public int getTotalAddedValues() { @SuppressWarnings("unchecked") @Nullable @Override - public T get(ExtendedAttributeKey key) { + public T get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey key) { return (T) super.get(key); } @Override - public Map, Object> asMap() { + public Map, Object> asMap() { // Because ExtendedAttributes is marked Immutable, IDEs may recognize this as redundant usage. // However, this class is private and is actually mutable, so we need to wrap with // unmodifiableMap anyways. We implement the immutable ExtendedAttributes for this class to @@ -91,12 +93,15 @@ public Map, Object> asMap() { } @Override - public ExtendedAttributesBuilder toBuilder() { - return ExtendedAttributes.builder().putAll(this); + public io.opentelemetry.api.incubator.common.ExtendedAttributesBuilder toBuilder() { + return io.opentelemetry.api.incubator.common.ExtendedAttributes.builder().putAll(this); } @Override - public void forEach(BiConsumer, ? super Object> action) { + public void forEach( + BiConsumer< + ? super io.opentelemetry.api.incubator.common.ExtendedAttributeKey, ? super Object> + action) { // https://github.com/open-telemetry/opentelemetry-java/issues/4161 // Help out android desugaring by having an explicit call to HashMap.forEach, when forEach is // just called through ExtendedAttributes.forEach desugaring is unable to correctly handle it. @@ -121,7 +126,7 @@ public String toString() { } /** Create an immutable copy of the extended attributes in this map. */ - public ExtendedAttributes immutableCopy() { - return ExtendedAttributes.builder().putAll(this).build(); + public io.opentelemetry.api.incubator.common.ExtendedAttributes immutableCopy() { + return io.opentelemetry.api.incubator.common.ExtendedAttributes.builder().putAll(this).build(); } } diff --git a/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java b/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java index 4d71f27394a..6a5eaae7cc3 100644 --- a/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java +++ b/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java @@ -9,11 +9,11 @@ import io.opentelemetry.api.common.KeyValue; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import java.nio.ByteBuffer; import java.util.List; import org.junit.jupiter.api.Test; +@SuppressWarnings("deprecation") class ExtendedAttributesValueTest { @Test @@ -22,9 +22,10 @@ void put_ByteArrayTruncation() { byte[] bytes = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Value value = Value.of(bytes); - map.put(ExtendedAttributeKey.valueKey("key"), value); + map.put(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key"), value); - Value result = map.get(ExtendedAttributeKey.valueKey("key")); + Value result = + map.get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key")); ByteBuffer buffer = (ByteBuffer) result.getValue(); byte[] resultBytes = new byte[buffer.remaining()]; buffer.get(resultBytes); @@ -37,9 +38,10 @@ void put_ValueArrayTruncation() { Value arrayValue = Value.of(Value.of("short"), Value.of("this is too long")); - map.put(ExtendedAttributeKey.valueKey("key"), arrayValue); + map.put(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key"), arrayValue); - Value result = map.get(ExtendedAttributeKey.valueKey("key")); + Value result = + map.get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key")); @SuppressWarnings("unchecked") List> resultList = (List>) result.getValue(); assertThat(resultList).hasSize(2); @@ -56,9 +58,11 @@ void put_ValueKeyValueListTruncation() { KeyValue.of("key1", Value.of("short")), KeyValue.of("key2", Value.of("this is too long"))); - map.put(ExtendedAttributeKey.valueKey("key"), kvListValue); + map.put( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key"), kvListValue); - Value result = map.get(ExtendedAttributeKey.valueKey("key")); + Value result = + map.get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key")); @SuppressWarnings("unchecked") List resultList = (List) result.getValue(); assertThat(resultList).hasSize(2); diff --git a/sdk/logs/build.gradle.kts b/sdk/logs/build.gradle.kts index b205b03e90e..62de7b3a136 100644 --- a/sdk/logs/build.gradle.kts +++ b/sdk/logs/build.gradle.kts @@ -39,4 +39,10 @@ tasks { check { dependsOn(testing.suites) } + // ExtendedSdkLogRecordData generated AutoValue class imports deprecated ExtendedAttributes. + // @SuppressWarnings can't suppress import statement warnings. + // TODO: remove after removing ExtendedAttributes + named("compileJava") { + options.compilerArgs.add("-Xlint:-deprecation") + } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java index d915cb81103..bbe119f217c 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java @@ -7,7 +7,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.Span; @@ -19,6 +18,7 @@ import javax.annotation.Nullable; /** SDK implementation of {@link ExtendedLogRecordBuilder}. */ +@SuppressWarnings("deprecation") final class ExtendedSdkLogRecordBuilder extends SdkLogRecordBuilder implements ExtendedLogRecordBuilder { @@ -108,7 +108,8 @@ public ExtendedSdkLogRecordBuilder setBody(Value value) { } @Override - public ExtendedSdkLogRecordBuilder setAttribute(ExtendedAttributeKey key, T value) { + public ExtendedSdkLogRecordBuilder setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value) { if (key == null || key.getKey().isEmpty() || value == null) { return this; } @@ -126,7 +127,8 @@ public ExtendedSdkLogRecordBuilder setAttribute(AttributeKey key, @Nullab if (key == null || key.getKey().isEmpty() || value == null) { return this; } - return setAttribute(ExtendedAttributeKey.fromAttributeKey(key), value); + return setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.fromAttributeKey(key), value); } @Override diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java index 14f1e9a3985..f3b5591f264 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java @@ -7,7 +7,6 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; @@ -19,6 +18,7 @@ @AutoValue @AutoValue.CopyAnnotations @Immutable +@SuppressWarnings("deprecation") abstract class ExtendedSdkLogRecordData implements ExtendedLogRecordData { ExtendedSdkLogRecordData() {} @@ -33,7 +33,7 @@ static ExtendedSdkLogRecordData create( Severity severity, @Nullable String severityText, @Nullable Value body, - ExtendedAttributes attributes, + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes, int totalAttributeCount) { return new AutoValue_ExtendedSdkLogRecordData( resource, diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java index daf4ab359ef..2d740be37f0 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java @@ -8,8 +8,6 @@ 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.internal.GuardedBy; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; @@ -22,6 +20,7 @@ import javax.annotation.concurrent.ThreadSafe; @ThreadSafe +@SuppressWarnings("deprecation") class ExtendedSdkReadWriteLogRecord extends SdkReadWriteLogRecord implements ExtendedReadWriteLogRecord { @@ -91,11 +90,13 @@ public ExtendedSdkReadWriteLogRecord setAttribute(AttributeKey key, T val if (key == null || key.getKey().isEmpty() || value == null) { return this; } - return setAttribute(ExtendedAttributeKey.fromAttributeKey(key), value); + return setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.fromAttributeKey(key), value); } @Override - public ExtendedSdkReadWriteLogRecord setAttribute(ExtendedAttributeKey key, T value) { + public ExtendedSdkReadWriteLogRecord setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value) { if (key == null || key.getKey().isEmpty() || value == null) { return this; } @@ -110,10 +111,11 @@ public ExtendedSdkReadWriteLogRecord setAttribute(ExtendedAttributeKey ke return this; } - private ExtendedAttributes getImmutableExtendedAttributes() { + private io.opentelemetry.api.incubator.common.ExtendedAttributes + getImmutableExtendedAttributes() { synchronized (lock) { if (extendedAttributes == null) { - return ExtendedAttributes.empty(); + return io.opentelemetry.api.incubator.common.ExtendedAttributes.empty(); } return extendedAttributes.immutableCopy(); } @@ -145,12 +147,13 @@ public Attributes getAttributes() { @Nullable @Override public T getAttribute(AttributeKey key) { - return getAttribute(ExtendedAttributeKey.fromAttributeKey(key)); + return getAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.fromAttributeKey(key)); } @Nullable @Override - public T getAttribute(ExtendedAttributeKey key) { + public T getAttribute(io.opentelemetry.api.incubator.common.ExtendedAttributeKey key) { synchronized (lock) { if (extendedAttributes == null || extendedAttributes.isEmpty()) { return null; @@ -160,7 +163,7 @@ public T getAttribute(ExtendedAttributeKey key) { } @Override - public ExtendedAttributes getExtendedAttributes() { + public io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes() { return getImmutableExtendedAttributes(); } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java index 65710807321..47642cc4c48 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java @@ -6,7 +6,6 @@ package io.opentelemetry.sdk.logs.data.internal; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.sdk.logs.data.LogRecordData; /** @@ -14,10 +13,14 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ +@SuppressWarnings("deprecation") public interface ExtendedLogRecordData extends LogRecordData { - /** Returns the attributes for this log, or {@link ExtendedAttributes#empty()} if unset. */ - ExtendedAttributes getExtendedAttributes(); + /** + * Returns the attributes for this log, or {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributes#empty()} if unset. + */ + io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes(); /** * Returns the attributes for this log, or {@link Attributes#empty()} if unset. diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java index 527c1e14063..c3137c76f19 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java @@ -5,8 +5,6 @@ package io.opentelemetry.sdk.logs.internal; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.sdk.logs.ReadWriteLogRecord; import io.opentelemetry.sdk.logs.data.internal.ExtendedLogRecordData; import javax.annotation.Nullable; @@ -19,6 +17,7 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ +@SuppressWarnings("deprecation") public interface ExtendedReadWriteLogRecord extends ReadWriteLogRecord { /** @@ -27,7 +26,8 @@ public interface ExtendedReadWriteLogRecord extends ReadWriteLogRecord { * *

    Note: the behavior of null values is undefined, and hence strongly discouraged. */ - ExtendedReadWriteLogRecord setAttribute(ExtendedAttributeKey key, T value); + ExtendedReadWriteLogRecord setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value); /** * Sets attributes to the {@link ReadWriteLogRecord}. If the {@link ReadWriteLogRecord} previously @@ -37,13 +37,16 @@ public interface ExtendedReadWriteLogRecord extends ReadWriteLogRecord { * @return this. */ @SuppressWarnings("unchecked") - default ExtendedReadWriteLogRecord setAllAttributes(ExtendedAttributes extendedAttributes) { + default ExtendedReadWriteLogRecord setAllAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes extendedAttributes) { if (extendedAttributes == null || extendedAttributes.isEmpty()) { return this; } extendedAttributes.forEach( (attributeKey, value) -> - this.setAttribute((ExtendedAttributeKey) attributeKey, value)); + this.setAttribute( + (io.opentelemetry.api.incubator.common.ExtendedAttributeKey) attributeKey, + value)); return this; } @@ -56,8 +59,11 @@ default ExtendedReadWriteLogRecord setAllAttributes(ExtendedAttributes extendedA * getAttributes().get(key) */ @Nullable - T getAttribute(ExtendedAttributeKey key); + T getAttribute(io.opentelemetry.api.incubator.common.ExtendedAttributeKey key); - /** Returns the attributes for this log, or {@link ExtendedAttributes#empty()} if unset. */ - ExtendedAttributes getExtendedAttributes(); + /** + * Returns the attributes for this log, or {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributes#empty()} if unset. + */ + io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes(); } diff --git a/sdk/testing/build.gradle.kts b/sdk/testing/build.gradle.kts index 44bbcad90d8..247e83aedb8 100644 --- a/sdk/testing/build.gradle.kts +++ b/sdk/testing/build.gradle.kts @@ -32,3 +32,12 @@ testing { } } } + +tasks { + // TestExtendedLogRecordData generated AutoValue class imports deprecated ExtendedAttributes. + // @SuppressWarnings can't suppress import statement warnings. + // TODO: remove after removing ExtendedAttributes + named("compileJava") { + options.compilerArgs.add("-Xlint:-deprecation") + } +} diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java index 914927c28be..963b7148bcb 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java @@ -8,7 +8,6 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; @@ -189,13 +188,17 @@ public Builder setBody(io.opentelemetry.sdk.logs.data.Body body) { /** Set the attributes. */ public Builder setAttributes(Attributes attributes) { - return setExtendedAttributes(ExtendedAttributes.builder().putAll(attributes).build()); + return setExtendedAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() + .putAll(attributes) + .build()); } /** Set the total attribute count. */ public abstract Builder setTotalAttributeCount(int totalAttributeCount); /** Set extended attributes. * */ - public abstract Builder setExtendedAttributes(ExtendedAttributes extendedAttributes); + public abstract Builder setExtendedAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes extendedAttributes); } }