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 761748ce206..6390138ce28 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 cbdac5429ef..22c6ffc6870 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..a4ea4acd059 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 @@ -17,6 +17,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 final class InternalExtendedAttributeKeyImpl implements ExtendedAttributeKey { private final ExtendedAttributeType type; @@ -115,7 +116,6 @@ private static int buildHashCode(ExtendedAttributeType type, String key) { * io.opentelemetry.api.common.AttributeType}. */ @Nullable - @SuppressWarnings("deprecation") // Supporting deprecated EXTENDED_ATTRIBUTES until removed public static AttributeKey toAttributeKey(ExtendedAttributeKey extendedAttributeKey) { switch (extendedAttributeKey.getType()) { case STRING: 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..77b7970ecf0 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 @@ -15,6 +15,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; +@SuppressWarnings("deprecation") class ExtendedDefaultLogger implements ExtendedLogger { private static final Logger INSTANCE = new ExtendedDefaultLogger(); 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..1e1f0872cbd 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 @@ -18,6 +18,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. 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..5837b5cda85 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 @@ -31,6 +31,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 = 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..704198c2474 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 @@ -32,6 +32,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 final class ExtendedAttributeKeyValueStatelessMarshaler implements StatelessMarshaler2, Object> { private static final ExtendedAttributeKeyValueStatelessMarshaler INSTANCE = @@ -142,7 +143,7 @@ private static class ValueStatelessMarshaler 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) { @@ -186,7 +187,7 @@ public int getBinarySerializedSize( } // Supporting deprecated EXTENDED_ATTRIBUTES type until removed - @SuppressWarnings({"unchecked", "deprecation"}) + @SuppressWarnings("unchecked") @Override public void writeTo( Serializer output, 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..4ee235aa1e1 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 @@ -27,6 +27,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; @@ -82,7 +83,7 @@ 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"}) + @SuppressWarnings("unchecked") private static KeyValueMarshaler create(ExtendedAttributeKey attributeKey, Object value) { byte[] keyUtf8; if (attributeKey.getKey().isEmpty()) { 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..233fa7eace9 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 @@ -24,6 +24,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 final class ExtendedAttributesMap extends HashMap, Object> implements ExtendedAttributes { 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..e3350b82efd 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 @@ -14,6 +14,7 @@ import java.util.List; import org.junit.jupiter.api.Test; +@SuppressWarnings("deprecation") class ExtendedAttributesValueTest { @Test 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 53818c7155c..edcc555623c 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 @@ -19,6 +19,7 @@ import javax.annotation.Nullable; /** SDK implementation of {@link ExtendedLogRecordBuilder}. */ +@SuppressWarnings("deprecation") final class ExtendedSdkLogRecordBuilder extends SdkLogRecordBuilder implements ExtendedLogRecordBuilder { 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 2daa873793e..842a7ec2ea6 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 @@ -20,6 +20,7 @@ @AutoValue @AutoValue.CopyAnnotations @Immutable +@SuppressWarnings("deprecation") abstract class ExtendedSdkLogRecordData implements ExtendedLogRecordData { ExtendedSdkLogRecordData() {} 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..be8417b0bb5 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 @@ -22,6 +22,7 @@ import javax.annotation.concurrent.ThreadSafe; @ThreadSafe +@SuppressWarnings("deprecation") class ExtendedSdkReadWriteLogRecord extends SdkReadWriteLogRecord implements ExtendedReadWriteLogRecord { 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..18e2c8f57a5 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 @@ -14,6 +14,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 ExtendedLogRecordData extends LogRecordData { /** Returns the attributes for this log, or {@link ExtendedAttributes#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..130bbc1471d 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 @@ -19,6 +19,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 { /** 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") + } +}