Skip to content

Commit c2cee4e

Browse files
committed
Deprecate ExtendedAttributes, ExtendedAttributeKey, ExtendedAttributeType, ExtendedAttributesBuilder
1 parent 6893380 commit c2cee4e

File tree

24 files changed

+381
-262
lines changed

24 files changed

+381
-262
lines changed

api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import javax.annotation.Nullable;
1919
import javax.annotation.concurrent.Immutable;
2020

21+
@SuppressWarnings("deprecation")
2122
@Immutable
2223
final class ArrayBackedExtendedAttributes
2324
extends ImmutableKeyValuePairs<ExtendedAttributeKey<?>, Object> implements ExtendedAttributes {

api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@
55

66
package io.opentelemetry.api.incubator.common;
77

8-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey;
9-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey;
10-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey;
11-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey;
12-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey;
13-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey;
14-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey;
15-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey;
16-
178
import io.opentelemetry.api.common.Value;
189
import io.opentelemetry.api.common.ValueType;
1910
import java.util.ArrayList;
2011
import java.util.Arrays;
2112
import java.util.List;
2213
import java.util.function.Predicate;
2314

15+
@SuppressWarnings("deprecation")
2416
class ArrayBackedExtendedAttributesBuilder implements ExtendedAttributesBuilder {
2517
private final List<Object> data;
2618

@@ -62,16 +54,16 @@ private void putValue(ExtendedAttributeKey<?> key, Value<?> valueObj) {
6254
String keyName = key.getKey();
6355
switch (valueObj.getType()) {
6456
case STRING:
65-
put(stringKey(keyName), ((Value<String>) valueObj).getValue());
57+
put(ExtendedAttributeKey.stringKey(keyName), ((Value<String>) valueObj).getValue());
6658
return;
6759
case LONG:
68-
put(longKey(keyName), ((Value<Long>) valueObj).getValue());
60+
put(ExtendedAttributeKey.longKey(keyName), ((Value<Long>) valueObj).getValue());
6961
return;
7062
case DOUBLE:
71-
put(doubleKey(keyName), ((Value<Double>) valueObj).getValue());
63+
put(ExtendedAttributeKey.doubleKey(keyName), ((Value<Double>) valueObj).getValue());
7264
return;
7365
case BOOLEAN:
74-
put(booleanKey(keyName), ((Value<Boolean>) valueObj).getValue());
66+
put(ExtendedAttributeKey.booleanKey(keyName), ((Value<Boolean>) valueObj).getValue());
7567
return;
7668
case ARRAY:
7769
List<Value<?>> arrayValues = (List<Value<?>>) valueObj.getValue();
@@ -82,28 +74,28 @@ private void putValue(ExtendedAttributeKey<?> key, Value<?> valueObj) {
8274
for (Value<?> v : arrayValues) {
8375
strings.add((String) v.getValue());
8476
}
85-
put(stringArrayKey(keyName), strings);
77+
put(ExtendedAttributeKey.stringArrayKey(keyName), strings);
8678
return;
8779
case LONG_ARRAY:
8880
List<Long> longs = new ArrayList<>(arrayValues.size());
8981
for (Value<?> v : arrayValues) {
9082
longs.add((Long) v.getValue());
9183
}
92-
put(longArrayKey(keyName), longs);
84+
put(ExtendedAttributeKey.longArrayKey(keyName), longs);
9385
return;
9486
case DOUBLE_ARRAY:
9587
List<Double> doubles = new ArrayList<>(arrayValues.size());
9688
for (Value<?> v : arrayValues) {
9789
doubles.add((Double) v.getValue());
9890
}
99-
put(doubleArrayKey(keyName), doubles);
91+
put(ExtendedAttributeKey.doubleArrayKey(keyName), doubles);
10092
return;
10193
case BOOLEAN_ARRAY:
10294
List<Boolean> booleans = new ArrayList<>(arrayValues.size());
10395
for (Value<?> v : arrayValues) {
10496
booleans.add((Boolean) v.getValue());
10597
}
106-
put(booleanArrayKey(keyName), booleans);
98+
put(ExtendedAttributeKey.booleanArrayKey(keyName), booleans);
10799
return;
108100
case VALUE:
109101
// Not coercible (empty, non-homogeneous, or unsupported element type)

api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
* </ul>
3131
*
3232
* @param <T> The type of value that can be set with the key.
33+
* @deprecated Use {@link AttributeKey} with {@link AttributeKey#valueKey(String)} instead. Complex
34+
* attributes were stabilized in version 1.59.0.
3335
*/
36+
@Deprecated
3437
@Immutable
3538
public interface ExtendedAttributeKey<T> {
3639
/** Returns the underlying String representation of the key. */

api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
* hence the types of values that are allowed for {@link ExtendedAttributes}.
1111
*
1212
* <p>This is a superset of {@link io.opentelemetry.api.common.AttributeType},
13+
*
14+
* @deprecated Use {@link io.opentelemetry.api.common.AttributeType} instead. Complex attributes
15+
* were stabilized in version 1.59.0.
1316
*/
17+
@Deprecated
1418
public enum ExtendedAttributeType {
1519
// Types copied AttributeType
1620
STRING,

api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@
4747
* {@link ExtendedAttributes}
4848
* <li>{@link #get(AttributeKey)} supports reading values using standard {@link AttributeKey}
4949
* </ul>
50+
*
51+
* @deprecated Use {@link Attributes} with {@link
52+
* io.opentelemetry.api.common.AttributeKey#valueKey(String)} instead. Complex attributes were
53+
* stabilized in version 1.59.0.
5054
*/
55+
@Deprecated
5156
@Immutable
5257
public interface ExtendedAttributes {
5358

api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@
55

66
package io.opentelemetry.api.incubator.common;
77

8-
import static io.opentelemetry.api.incubator.common.ArrayBackedExtendedAttributesBuilder.toList;
9-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey;
10-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey;
11-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey;
12-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey;
13-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey;
14-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey;
15-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey;
16-
import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey;
17-
188
import io.opentelemetry.api.common.AttributeKey;
199
import io.opentelemetry.api.common.Attributes;
2010
import io.opentelemetry.api.common.Value;
2111
import java.util.Arrays;
2212
import java.util.List;
2313
import java.util.function.Predicate;
2414

25-
/** A builder of {@link ExtendedAttributes} supporting an arbitrary number of key-value pairs. */
15+
/**
16+
* A builder of {@link ExtendedAttributes} supporting an arbitrary number of key-value pairs.
17+
*
18+
* @deprecated Use {@link io.opentelemetry.api.common.AttributesBuilder} with {@link
19+
* io.opentelemetry.api.common.AttributeKey#valueKey(String)} instead. Complex attributes were
20+
* stabilized in version 1.59.0.
21+
*/
22+
@Deprecated
2623
public interface ExtendedAttributesBuilder {
2724
/** Create the {@link ExtendedAttributes} from this. */
2825
ExtendedAttributes build();
@@ -85,7 +82,7 @@ default <T> ExtendedAttributesBuilder put(AttributeKey<T> key, T value) {
8582
* @return this Builder
8683
*/
8784
default ExtendedAttributesBuilder put(String key, String value) {
88-
return put(stringKey(key), value);
85+
return put(ExtendedAttributeKey.stringKey(key), value);
8986
}
9087

9188
/**
@@ -97,7 +94,7 @@ default ExtendedAttributesBuilder put(String key, String value) {
9794
* @return this Builder
9895
*/
9996
default ExtendedAttributesBuilder put(String key, long value) {
100-
return put(longKey(key), value);
97+
return put(ExtendedAttributeKey.longKey(key), value);
10198
}
10299

103100
/**
@@ -109,7 +106,7 @@ default ExtendedAttributesBuilder put(String key, long value) {
109106
* @return this Builder
110107
*/
111108
default ExtendedAttributesBuilder put(String key, double value) {
112-
return put(doubleKey(key), value);
109+
return put(ExtendedAttributeKey.doubleKey(key), value);
113110
}
114111

115112
/**
@@ -121,7 +118,7 @@ default ExtendedAttributesBuilder put(String key, double value) {
121118
* @return this Builder
122119
*/
123120
default ExtendedAttributesBuilder put(String key, boolean value) {
124-
return put(booleanKey(key), value);
121+
return put(ExtendedAttributeKey.booleanKey(key), value);
125122
}
126123

127124
/**
@@ -151,7 +148,7 @@ default ExtendedAttributesBuilder put(String key, String... value) {
151148
if (value == null) {
152149
return this;
153150
}
154-
return put(stringArrayKey(key), Arrays.asList(value));
151+
return put(ExtendedAttributeKey.stringArrayKey(key), Arrays.asList(value));
155152
}
156153

157154
/**
@@ -179,7 +176,8 @@ default ExtendedAttributesBuilder put(String key, long... value) {
179176
if (value == null) {
180177
return this;
181178
}
182-
return put(longArrayKey(key), toList(value));
179+
return put(
180+
ExtendedAttributeKey.longArrayKey(key), ArrayBackedExtendedAttributesBuilder.toList(value));
183181
}
184182

185183
/**
@@ -194,7 +192,9 @@ default ExtendedAttributesBuilder put(String key, double... value) {
194192
if (value == null) {
195193
return this;
196194
}
197-
return put(doubleArrayKey(key), toList(value));
195+
return put(
196+
ExtendedAttributeKey.doubleArrayKey(key),
197+
ArrayBackedExtendedAttributesBuilder.toList(value));
198198
}
199199

200200
/**
@@ -209,7 +209,9 @@ default ExtendedAttributesBuilder put(String key, boolean... value) {
209209
if (value == null) {
210210
return this;
211211
}
212-
return put(booleanArrayKey(key), toList(value));
212+
return put(
213+
ExtendedAttributeKey.booleanArrayKey(key),
214+
ArrayBackedExtendedAttributesBuilder.toList(value));
213215
}
214216

215217
/**

api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import io.opentelemetry.api.common.AttributeKey;
99
import io.opentelemetry.api.common.AttributeType;
10-
import io.opentelemetry.api.incubator.common.ExtendedAttributeKey;
11-
import io.opentelemetry.api.incubator.common.ExtendedAttributeType;
1210
import io.opentelemetry.api.internal.InternalAttributeKeyImpl;
1311
import java.nio.charset.StandardCharsets;
1412
import javax.annotation.Nullable;
@@ -17,16 +15,19 @@
1715
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
1816
* any time.
1917
*/
20-
public final class InternalExtendedAttributeKeyImpl<T> implements ExtendedAttributeKey<T> {
18+
@SuppressWarnings("deprecation")
19+
public final class InternalExtendedAttributeKeyImpl<T>
20+
implements io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> {
2121

22-
private final ExtendedAttributeType type;
22+
private final io.opentelemetry.api.incubator.common.ExtendedAttributeType type;
2323
private final String key;
2424
private final int hashCode;
2525

2626
@Nullable private byte[] keyUtf8;
2727
@Nullable private AttributeKey<T> attributeKey;
2828

29-
private InternalExtendedAttributeKeyImpl(ExtendedAttributeType type, String key) {
29+
private InternalExtendedAttributeKeyImpl(
30+
io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) {
3031
if (type == null) {
3132
throw new NullPointerException("Null type");
3233
}
@@ -38,13 +39,13 @@ private InternalExtendedAttributeKeyImpl(ExtendedAttributeType type, String key)
3839
this.hashCode = buildHashCode(type, key);
3940
}
4041

41-
public static <T> ExtendedAttributeKey<T> create(
42-
@Nullable String key, ExtendedAttributeType type) {
42+
public static <T> io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> create(
43+
@Nullable String key, io.opentelemetry.api.incubator.common.ExtendedAttributeType type) {
4344
return new InternalExtendedAttributeKeyImpl<>(type, key != null ? key : "");
4445
}
4546

4647
@Override
47-
public ExtendedAttributeType getType() {
48+
public io.opentelemetry.api.incubator.common.ExtendedAttributeType getType() {
4849
return type;
4950
}
5051

@@ -100,7 +101,8 @@ private int buildHashCode() {
100101
return buildHashCode(type, key);
101102
}
102103

103-
private static int buildHashCode(ExtendedAttributeType type, String key) {
104+
private static int buildHashCode(
105+
io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) {
104106
int result = 1;
105107
result *= 1000003;
106108
result ^= type.hashCode();
@@ -110,13 +112,13 @@ private static int buildHashCode(ExtendedAttributeType type, String key) {
110112
}
111113

112114
/**
113-
* Return the equivalent {@link AttributeKey} for the {@link ExtendedAttributeKey}, or {@code
114-
* null} if the {@link #getType()} has no equivalent {@link
115-
* io.opentelemetry.api.common.AttributeType}.
115+
* Return the equivalent {@link AttributeKey} for the {@link
116+
* io.opentelemetry.api.incubator.common.ExtendedAttributeKey}, or {@code null} if the {@link
117+
* #getType()} has no equivalent {@link io.opentelemetry.api.common.AttributeType}.
116118
*/
117119
@Nullable
118-
@SuppressWarnings("deprecation") // Supporting deprecated EXTENDED_ATTRIBUTES until removed
119-
public static <T> AttributeKey<T> toAttributeKey(ExtendedAttributeKey<T> extendedAttributeKey) {
120+
public static <T> AttributeKey<T> toAttributeKey(
121+
io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> extendedAttributeKey) {
120122
switch (extendedAttributeKey.getType()) {
121123
case STRING:
122124
return InternalAttributeKeyImpl.create(extendedAttributeKey.getKey(), AttributeType.STRING);
@@ -148,36 +150,50 @@ public static <T> AttributeKey<T> toAttributeKey(ExtendedAttributeKey<T> extende
148150
"Unrecognized extendedAttributeKey type: " + extendedAttributeKey.getType());
149151
}
150152

151-
/** Return the equivalent {@link ExtendedAttributeKey} for the {@link AttributeKey}. */
152-
public static <T> ExtendedAttributeKey<T> toExtendedAttributeKey(AttributeKey<T> attributeKey) {
153+
/**
154+
* Return the equivalent {@link io.opentelemetry.api.incubator.common.ExtendedAttributeKey} for
155+
* the {@link AttributeKey}.
156+
*/
157+
public static <T>
158+
io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> toExtendedAttributeKey(
159+
AttributeKey<T> attributeKey) {
153160
switch (attributeKey.getType()) {
154161
case STRING:
155162
return InternalExtendedAttributeKeyImpl.create(
156-
attributeKey.getKey(), ExtendedAttributeType.STRING);
163+
attributeKey.getKey(),
164+
io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING);
157165
case BOOLEAN:
158166
return InternalExtendedAttributeKeyImpl.create(
159-
attributeKey.getKey(), ExtendedAttributeType.BOOLEAN);
167+
attributeKey.getKey(),
168+
io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN);
160169
case LONG:
161170
return InternalExtendedAttributeKeyImpl.create(
162-
attributeKey.getKey(), ExtendedAttributeType.LONG);
171+
attributeKey.getKey(),
172+
io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG);
163173
case DOUBLE:
164174
return InternalExtendedAttributeKeyImpl.create(
165-
attributeKey.getKey(), ExtendedAttributeType.DOUBLE);
175+
attributeKey.getKey(),
176+
io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE);
166177
case STRING_ARRAY:
167178
return InternalExtendedAttributeKeyImpl.create(
168-
attributeKey.getKey(), ExtendedAttributeType.STRING_ARRAY);
179+
attributeKey.getKey(),
180+
io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING_ARRAY);
169181
case BOOLEAN_ARRAY:
170182
return InternalExtendedAttributeKeyImpl.create(
171-
attributeKey.getKey(), ExtendedAttributeType.BOOLEAN_ARRAY);
183+
attributeKey.getKey(),
184+
io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN_ARRAY);
172185
case LONG_ARRAY:
173186
return InternalExtendedAttributeKeyImpl.create(
174-
attributeKey.getKey(), ExtendedAttributeType.LONG_ARRAY);
187+
attributeKey.getKey(),
188+
io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG_ARRAY);
175189
case DOUBLE_ARRAY:
176190
return InternalExtendedAttributeKeyImpl.create(
177-
attributeKey.getKey(), ExtendedAttributeType.DOUBLE_ARRAY);
191+
attributeKey.getKey(),
192+
io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE_ARRAY);
178193
case VALUE:
179194
return InternalExtendedAttributeKeyImpl.create(
180-
attributeKey.getKey(), ExtendedAttributeType.VALUE);
195+
attributeKey.getKey(),
196+
io.opentelemetry.api.incubator.common.ExtendedAttributeType.VALUE);
181197
}
182198
throw new IllegalArgumentException("Unrecognized attributeKey type: " + attributeKey.getType());
183199
}

api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
import io.opentelemetry.api.common.AttributeKey;
99
import io.opentelemetry.api.common.Value;
10-
import io.opentelemetry.api.incubator.common.ExtendedAttributeKey;
1110
import io.opentelemetry.api.logs.Logger;
1211
import io.opentelemetry.api.logs.Severity;
1312
import io.opentelemetry.context.Context;
1413
import java.time.Instant;
1514
import java.util.concurrent.TimeUnit;
1615
import javax.annotation.Nullable;
1716

17+
@SuppressWarnings("deprecation")
1818
class ExtendedDefaultLogger implements ExtendedLogger {
1919

2020
private static final Logger INSTANCE = new ExtendedDefaultLogger();
@@ -52,7 +52,8 @@ public ExtendedLogRecordBuilder setException(Throwable throwable) {
5252
}
5353

5454
@Override
55-
public <T> ExtendedLogRecordBuilder setAttribute(ExtendedAttributeKey<T> key, T value) {
55+
public <T> ExtendedLogRecordBuilder setAttribute(
56+
io.opentelemetry.api.incubator.common.ExtendedAttributeKey<T> key, T value) {
5657
return this;
5758
}
5859

0 commit comments

Comments
 (0)