Skip to content

Commit 2b69000

Browse files
committed
javadoc
1 parent 0eac215 commit 2b69000

File tree

19 files changed

+488
-616
lines changed

19 files changed

+488
-616
lines changed

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

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
import io.opentelemetry.api.internal.ImmutableKeyValuePairs;
99
import java.util.ArrayList;
10-
import java.util.Collections;
1110
import java.util.Comparator;
12-
import java.util.List;
1311
import javax.annotation.Nullable;
1412
import javax.annotation.concurrent.Immutable;
1513

@@ -47,117 +45,9 @@ public AttributesBuilder toBuilder() {
4745
@Override
4846
@Nullable
4947
public <T> T get(AttributeKey<T> key) {
50-
if (key == null) {
51-
return null;
52-
}
53-
if (key.getType() == AttributeType.VALUE) {
54-
return (T) getAsValue(key.getKey());
55-
}
56-
// Check if we're looking for an array type but have a VALUE with empty array
57-
if (isArrayType(key.getType())) {
58-
T value = (T) super.get(key);
59-
if (value == null) {
60-
// Check if there's a VALUE with the same key that contains an empty array
61-
Value<?> valueAttr = getValueAttribute(key.getKey());
62-
if (valueAttr != null && isEmptyArray(valueAttr)) {
63-
return (T) Collections.emptyList();
64-
}
65-
}
66-
return value;
67-
}
6848
return (T) super.get(key);
6949
}
7050

71-
private static boolean isArrayType(AttributeType type) {
72-
return type == AttributeType.STRING_ARRAY
73-
|| type == AttributeType.LONG_ARRAY
74-
|| type == AttributeType.DOUBLE_ARRAY
75-
|| type == AttributeType.BOOLEAN_ARRAY;
76-
}
77-
78-
@Nullable
79-
private Value<?> getValueAttribute(String keyName) {
80-
List<Object> data = data();
81-
for (int i = 0; i < data.size(); i += 2) {
82-
AttributeKey<?> currentKey = (AttributeKey<?>) data.get(i);
83-
if (currentKey.getKey().equals(keyName) && currentKey.getType() == AttributeType.VALUE) {
84-
return (Value<?>) data.get(i + 1);
85-
}
86-
}
87-
return null;
88-
}
89-
90-
private static boolean isEmptyArray(Value<?> value) {
91-
if (value.getType() != ValueType.ARRAY) {
92-
return false;
93-
}
94-
@SuppressWarnings("unchecked")
95-
List<Value<?>> arrayValues = (List<Value<?>>) value.getValue();
96-
return arrayValues.isEmpty();
97-
}
98-
99-
@Nullable
100-
private Value<?> getAsValue(String keyName) {
101-
// Find any attribute with the same key name and convert it to Value
102-
List<Object> data = data();
103-
for (int i = 0; i < data.size(); i += 2) {
104-
AttributeKey<?> currentKey = (AttributeKey<?>) data.get(i);
105-
if (currentKey.getKey().equals(keyName)) {
106-
Object value = data.get(i + 1);
107-
return asValue(currentKey.getType(), value);
108-
}
109-
}
110-
return null;
111-
}
112-
113-
@SuppressWarnings("unchecked")
114-
@Nullable
115-
private static Value<?> asValue(AttributeType type, Object value) {
116-
switch (type) {
117-
case STRING:
118-
return Value.of((String) value);
119-
case LONG:
120-
return Value.of((Long) value);
121-
case DOUBLE:
122-
return Value.of((Double) value);
123-
case BOOLEAN:
124-
return Value.of((Boolean) value);
125-
case STRING_ARRAY:
126-
List<String> stringList = (List<String>) value;
127-
Value<?>[] stringValues = new Value<?>[stringList.size()];
128-
for (int i = 0; i < stringList.size(); i++) {
129-
stringValues[i] = Value.of(stringList.get(i));
130-
}
131-
return Value.of(stringValues);
132-
case LONG_ARRAY:
133-
List<Long> longList = (List<Long>) value;
134-
Value<?>[] longValues = new Value<?>[longList.size()];
135-
for (int i = 0; i < longList.size(); i++) {
136-
longValues[i] = Value.of(longList.get(i));
137-
}
138-
return Value.of(longValues);
139-
case DOUBLE_ARRAY:
140-
List<Double> doubleList = (List<Double>) value;
141-
Value<?>[] doubleValues = new Value<?>[doubleList.size()];
142-
for (int i = 0; i < doubleList.size(); i++) {
143-
doubleValues[i] = Value.of(doubleList.get(i));
144-
}
145-
return Value.of(doubleValues);
146-
case BOOLEAN_ARRAY:
147-
List<Boolean> booleanList = (List<Boolean>) value;
148-
Value<?>[] booleanValues = new Value<?>[booleanList.size()];
149-
for (int i = 0; i < booleanList.size(); i++) {
150-
booleanValues[i] = Value.of(booleanList.get(i));
151-
}
152-
return Value.of(booleanValues);
153-
case VALUE:
154-
// Already a Value
155-
return (Value<?>) value;
156-
}
157-
// Should not reach here
158-
return null;
159-
}
160-
16151
static Attributes sortAndFilterToAttributes(Object... data) {
16252
// null out any empty keys or keys with null values
16353
// so they will then be removed by the sortAndFilter method.

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

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55

66
package io.opentelemetry.api.common;
77

8-
import static io.opentelemetry.api.common.AttributeKey.booleanArrayKey;
9-
import static io.opentelemetry.api.common.AttributeKey.booleanKey;
10-
import static io.opentelemetry.api.common.AttributeKey.doubleArrayKey;
11-
import static io.opentelemetry.api.common.AttributeKey.doubleKey;
12-
import static io.opentelemetry.api.common.AttributeKey.longArrayKey;
13-
import static io.opentelemetry.api.common.AttributeKey.longKey;
14-
import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
15-
import static io.opentelemetry.api.common.AttributeKey.stringKey;
16-
178
import java.util.ArrayList;
189
import java.util.Arrays;
1910
import java.util.List;
@@ -52,122 +43,11 @@ public <T> AttributesBuilder put(AttributeKey<T> key, @Nullable T value) {
5243
if (key == null || key.getKey().isEmpty() || value == null) {
5344
return this;
5445
}
55-
if (key.getType() == AttributeType.VALUE && value instanceof Value) {
56-
putValue(key, (Value<?>) value);
57-
return this;
58-
}
5946
data.add(key);
6047
data.add(value);
6148
return this;
6249
}
6350

64-
private void putValue(AttributeKey<?> key, Value<?> valueObj) {
65-
// Convert VALUE type to narrower type when possible
66-
String keyName = key.getKey();
67-
switch (valueObj.getType()) {
68-
case STRING:
69-
data.add(stringKey(keyName));
70-
data.add(valueObj.getValue());
71-
return;
72-
case LONG:
73-
data.add(longKey(keyName));
74-
data.add(valueObj.getValue());
75-
return;
76-
case DOUBLE:
77-
data.add(doubleKey(keyName));
78-
data.add(valueObj.getValue());
79-
return;
80-
case BOOLEAN:
81-
data.add(booleanKey(keyName));
82-
data.add(valueObj.getValue());
83-
return;
84-
case ARRAY:
85-
@SuppressWarnings("unchecked")
86-
List<Value<?>> arrayValues = (List<Value<?>>) valueObj.getValue();
87-
AttributeType attributeType = attributeType(arrayValues);
88-
switch (attributeType) {
89-
case STRING_ARRAY:
90-
List<String> strings = new ArrayList<>();
91-
for (Value<?> v : arrayValues) {
92-
strings.add((String) v.getValue());
93-
}
94-
data.add(stringArrayKey(keyName));
95-
data.add(strings);
96-
return;
97-
case LONG_ARRAY:
98-
List<Long> longs = new ArrayList<>();
99-
for (Value<?> v : arrayValues) {
100-
longs.add((Long) v.getValue());
101-
}
102-
data.add(longArrayKey(keyName));
103-
data.add(longs);
104-
return;
105-
case DOUBLE_ARRAY:
106-
List<Double> doubles = new ArrayList<>();
107-
for (Value<?> v : arrayValues) {
108-
doubles.add((Double) v.getValue());
109-
}
110-
data.add(doubleArrayKey(keyName));
111-
data.add(doubles);
112-
return;
113-
case BOOLEAN_ARRAY:
114-
List<Boolean> booleans = new ArrayList<>();
115-
for (Value<?> v : arrayValues) {
116-
booleans.add((Boolean) v.getValue());
117-
}
118-
data.add(booleanArrayKey(keyName));
119-
data.add(booleans);
120-
return;
121-
case VALUE:
122-
// Not coercible (empty, non-homogeneous, or unsupported element type)
123-
// TODO when empty, retrieve it when asked for any kind of array?
124-
data.add(key);
125-
data.add(valueObj);
126-
return;
127-
default:
128-
throw new IllegalArgumentException("Unexpected array attribute type: " + attributeType);
129-
}
130-
case KEY_VALUE_LIST:
131-
case BYTES:
132-
// Keep as VALUE type
133-
data.add(key);
134-
data.add(valueObj);
135-
return;
136-
}
137-
}
138-
139-
/**
140-
* Returns the AttributeType for a homogeneous array (STRING_ARRAY, LONG_ARRAY, DOUBLE_ARRAY, or
141-
* BOOLEAN_ARRAY), or VALUE if the array is empty, non-homogeneous, or contains unsupported
142-
* element types.
143-
*/
144-
private static AttributeType attributeType(List<Value<?>> arrayValues) {
145-
if (arrayValues.isEmpty()) {
146-
return AttributeType.VALUE;
147-
}
148-
ValueType elementType = arrayValues.get(0).getType();
149-
for (Value<?> v : arrayValues) {
150-
if (v.getType() != elementType) {
151-
return AttributeType.VALUE;
152-
}
153-
}
154-
switch (elementType) {
155-
case STRING:
156-
return AttributeType.STRING_ARRAY;
157-
case LONG:
158-
return AttributeType.LONG_ARRAY;
159-
case DOUBLE:
160-
return AttributeType.DOUBLE_ARRAY;
161-
case BOOLEAN:
162-
return AttributeType.BOOLEAN_ARRAY;
163-
case ARRAY:
164-
case KEY_VALUE_LIST:
165-
case BYTES:
166-
return AttributeType.VALUE;
167-
}
168-
throw new IllegalArgumentException("Unsupported element type: " + elementType);
169-
}
170-
17151
@Override
17252
@SuppressWarnings({"unchecked", "rawtypes"})
17353
public AttributesBuilder putAll(Attributes attributes) {

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

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

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,5 @@ public enum AttributeType {
1717
STRING_ARRAY,
1818
BOOLEAN_ARRAY,
1919
LONG_ARRAY,
20-
DOUBLE_ARRAY,
21-
/**
22-
* Simple attributes ({@link AttributeType#STRING}, {@link AttributeType#LONG}, {@link
23-
* AttributeType#DOUBLE}, {@link AttributeType#BOOLEAN}, {@link AttributeType#STRING_ARRAY},
24-
* {@link AttributeType#LONG_ARRAY}, {@link AttributeType#DOUBLE_ARRAY}, {@link
25-
* AttributeType#BOOLEAN_ARRAY}) SHOULD be used whenever possible. Instrumentations SHOULD assume
26-
* that backends do not index individual properties of complex attributes, that querying or
27-
* aggregating on such properties is inefficient and complicated, and that reporting complex
28-
* attributes carries higher performance overhead.
29-
*/
30-
VALUE
20+
DOUBLE_ARRAY
3121
}

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

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,57 +33,11 @@
3333
@Immutable
3434
public interface Attributes {
3535

36-
/**
37-
* Returns the value for the given {@link AttributeKey}, or {@code null} if not found.
38-
*
39-
* <p>Note: this method will automatically return the corresponding {@link Value} instance when
40-
* passed a key of type {@link AttributeType#VALUE} and a simple attribute is found. This is the
41-
* inverse of {@link AttributesBuilder#put(AttributeKey, Object)} when the key is {@link
42-
* AttributeType#VALUE}.
43-
*
44-
* <ul>
45-
* <li>If {@code put(AttributeKey.stringKey("key"), "a")} was called, then {@code
46-
* get(AttributeKey.valueKey("key"))} returns {@code Value.of("a")}.
47-
* <li>If {@code put(AttributeKey.longKey("key"), 1L)} was called, then {@code
48-
* get(AttributeKey.valueKey("key"))} returns {@code Value.of(1L)}.
49-
* <li>If {@code put(AttributeKey.doubleKey("key"), 1.0)} was called, then {@code
50-
* get(AttributeKey.valueKey("key"))} returns {@code Value.of(1.0)}.
51-
* <li>If {@code put(AttributeKey.booleanKey("key"), true)} was called, then {@code
52-
* get(AttributeKey.valueKey("key"))} returns {@code Value.of(true)}.
53-
* <li>If {@code put(AttributeKey.stringArrayKey("key"), Arrays.asList("a", "b"))} was called,
54-
* then {@code get(AttributeKey.valueKey("key"))} returns {@code Value.of(Value.of("a"),
55-
* Value.of("b"))}.
56-
* <li>If {@code put(AttributeKey.longArrayKey("key"), Arrays.asList(1L, 2L))} was called, then
57-
* {@code get(AttributeKey.valueKey("key"))} returns {@code Value.of(Value.of(1L),
58-
* Value.of(2L))}.
59-
* <li>If {@code put(AttributeKey.doubleArrayKey("key"), Arrays.asList(1.0, 2.0))} was called,
60-
* then {@code get(AttributeKey.valueKey("key"))} returns {@code Value.of(Value.of(1.0),
61-
* Value.of(2.0))}.
62-
* <li>If {@code put(AttributeKey.booleanArrayKey("key"), Arrays.asList(true, false))} was
63-
* called, then {@code get(AttributeKey.valueKey("key"))} returns {@code
64-
* Value.of(Value.of(true), Value.of(false))}.
65-
* </ul>
66-
*
67-
* Further, if {@code put(AttributeKey.valueKey("key"), Value.of(emptyList()))} was called, then
68-
*
69-
* <ul>
70-
* <li>{@code get(AttributeKey.stringArrayKey("key"))}
71-
* <li>{@code get(AttributeKey.longArrayKey("key"))}
72-
* <li>{@code get(AttributeKey.booleanArrayKey("key"))}
73-
* <li>{@code get(AttributeKey.doubleArrayKey("key"))}
74-
* </ul>
75-
*
76-
* all return an empty list (as opposed to {@code null}).
77-
*/
36+
/** Returns the value for the given {@link AttributeKey}, or {@code null} if not found. */
7837
@Nullable
7938
<T> T get(AttributeKey<T> key);
8039

81-
/**
82-
* Iterates over all the key-value pairs of attributes contained by this instance.
83-
*
84-
* <p>Note: {@link AttributeType#VALUE} attributes will be represented as simple attributes if
85-
* possible. See {@link AttributesBuilder#put(AttributeKey, Object)} for more details.
86-
*/
40+
/** Iterates over all the key-value pairs of attributes contained by this instance. */
8741
void forEach(BiConsumer<? super AttributeKey<?>, ? super Object> consumer);
8842

8943
/** The number of attributes contained in this. */
@@ -92,12 +46,7 @@ public interface Attributes {
9246
/** Whether there are any attributes contained in this. */
9347
boolean isEmpty();
9448

95-
/**
96-
* Returns a read-only view of this {@link Attributes} as a {@link Map}.
97-
*
98-
* <p>Note: {@link AttributeType#VALUE} attributes will be represented as simple attributes in
99-
* this map if possible. See {@link AttributesBuilder#put(AttributeKey, Object)} for more details.
100-
*/
49+
/** Returns a read-only view of this {@link Attributes} as a {@link Map}. */
10150
Map<AttributeKey<?>, Object> asMap();
10251

10352
/** Returns a {@link Attributes} instance with no attributes. */

0 commit comments

Comments
 (0)