Skip to content

Commit b36e1ef

Browse files
committed
progress
1 parent ea2155b commit b36e1ef

File tree

40 files changed

+1177
-390
lines changed

40 files changed

+1177
-390
lines changed

api/all/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ dependencies {
1919

2020
testImplementation("edu.berkeley.cs.jqf:jqf-fuzz")
2121
testImplementation("com.google.guava:guava-testlib")
22-
testImplementation(project(":sdk:all"))
23-
testImplementation(project(":sdk:testing"))
2422
}
2523

2624
tasks.test {

api/all/src/test/java/io/opentelemetry/api/logs/DefaultLoggerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
package io.opentelemetry.api.logs;
77

88
import io.opentelemetry.api.testing.internal.AbstractDefaultLoggerTest;
9-
import org.junit.jupiter.api.Disabled;
109

11-
@Disabled
1210
class DefaultLoggerTest extends AbstractDefaultLoggerTest {
1311

1412
@Override

api/all/src/test/java/io/opentelemetry/api/trace/DefaultTracerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
package io.opentelemetry.api.trace;
77

88
import io.opentelemetry.api.testing.internal.AbstractDefaultTracerTest;
9-
import org.junit.jupiter.api.Disabled;
109

11-
@Disabled
1210
class DefaultTracerTest extends AbstractDefaultTracerTest {
1311

1412
@Override

api/incubator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Experimental APIs, including Event API, extended Log Bridge APIs, extended Metri
77
Features:
88

99
* Check if logger is enabled before emitting logs to avoid unnecessary computation
10+
* Add extended attributes to log records to encode complex data structures
1011

1112
See [ExtendedLogsBridgeApiUsageTest](./src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java).
1213

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,25 @@
1111
import javax.annotation.Nullable;
1212
import javax.annotation.concurrent.Immutable;
1313

14-
/** TODO. */
14+
/**
15+
* This interface provides a handle for setting the values of {@link ExtendedAttributes}. The type
16+
* of value that can be set with an implementation of this key is denoted by the type parameter.
17+
*
18+
* <p>Implementations MUST be immutable, as these are used as the keys to Maps.
19+
*
20+
* <p>The allowed {@link #getType()}s is a superset of those allowed in {@link AttributeKey}.
21+
*
22+
* <p>Convenience methods are provided for translating to / from {@link AttributeKey}:
23+
*
24+
* <ul>
25+
* <li>{@link #asAttributeKey()} converts from {@link ExtendedAttributeKey} to {@link
26+
* AttributeKey}
27+
* <li>{@link #fromAttributeKey(AttributeKey)} converts from {@link AttributeKey} to {@link
28+
* ExtendedAttributeKey}
29+
* </ul>
30+
*
31+
* @param <T> The type of value that can be set with the key.
32+
*/
1533
@Immutable
1634
public interface ExtendedAttributeKey<T> {
1735
/** Returns the underlying String representation of the key. */
@@ -20,11 +38,17 @@ public interface ExtendedAttributeKey<T> {
2038
/** Returns the type of attribute for this key. Useful for building switch statements. */
2139
ExtendedAttributeType getType();
2240

41+
/**
42+
* Return the equivalent {@link AttributeKey}, or {@code null} if the {@link #getType()} has no
43+
* equivalent {@link io.opentelemetry.api.common.AttributeType}.
44+
*/
2345
@Nullable
2446
default AttributeKey<T> asAttributeKey() {
2547
return InternalExtendedAttributeKeyImpl.toAttributeKey(this);
2648
}
2749

50+
/** Return an ExtendedAttributeKey equivalent to the {@code attributeKey}. */
51+
// TODO (jack-berg): remove once AttributeKey.asExtendedAttributeKey is available
2852
static <T> ExtendedAttributeKey<T> fromAttributeKey(AttributeKey<T> attributeKey) {
2953
return InternalExtendedAttributeKeyImpl.fromAttributeKey(attributeKey);
3054
}
@@ -70,12 +94,7 @@ static ExtendedAttributeKey<List<Double>> doubleArrayKey(String key) {
7094
}
7195

7296
/** Returns a new ExtendedAttributeKey for Map valued attributes. */
73-
static ExtendedAttributeKey<ExtendedAttributes> mapKey(String key) {
74-
return InternalExtendedAttributeKeyImpl.create(key, ExtendedAttributeType.MAP);
75-
}
76-
77-
/** Returns a new ExtendedAttributeKey for Map array valued attributes. */
78-
static ExtendedAttributeKey<List<ExtendedAttributes>> mapArrayKey(String key) {
79-
return InternalExtendedAttributeKeyImpl.create(key, ExtendedAttributeType.MAP_ARRAY);
97+
static ExtendedAttributeKey<ExtendedAttributes> extendedAttributesKey(String key) {
98+
return InternalExtendedAttributeKeyImpl.create(key, ExtendedAttributeType.EXTENDED_ATTRIBUTES);
8099
}
81100
}

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

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

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

8-
/** TODO. */
8+
/**
9+
* An enum that represents all the possible value types for an {@link ExtendedAttributeKey} and
10+
* hence the types of values that are allowed for {@link ExtendedAttributes}.
11+
*
12+
* <p>This is a superset of {@link io.opentelemetry.api.common.AttributeType},
13+
*/
914
public enum ExtendedAttributeType {
15+
// Types copied AttributeType
1016
STRING,
1117
BOOLEAN,
1218
LONG,
@@ -15,6 +21,6 @@ public enum ExtendedAttributeType {
1521
BOOLEAN_ARRAY,
1622
LONG_ARRAY,
1723
DOUBLE_ARRAY,
18-
MAP,
19-
MAP_ARRAY;
24+
// Extended types unique to ExtendedAttributes
25+
EXTENDED_ATTRIBUTES;
2026
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,47 @@
77

88
import io.opentelemetry.api.common.AttributeKey;
99
import io.opentelemetry.api.common.Attributes;
10+
import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder;
1011
import java.util.Map;
1112
import java.util.function.BiConsumer;
1213
import javax.annotation.Nullable;
1314
import javax.annotation.concurrent.Immutable;
1415

16+
/**
17+
* An immutable container for extended attributes.
18+
*
19+
* <p>"extended" refers an extended set of allowed value types compared to standard {@link
20+
* Attributes}. Notably, {@link ExtendedAttributes} values can be of type {@link
21+
* ExtendedAttributeType#EXTENDED_ATTRIBUTES}, allowing nested {@link ExtendedAttributes} of
22+
* arbitrary depth.
23+
*
24+
* <p>Where standard {@link Attributes} are accepted everyone that OpenTelemetry represents key /
25+
* value pairs, {@link ExtendedAttributes} are only accepted in select places, such as log records
26+
* (e.g. {@link ExtendedLogRecordBuilder#setAttribute(ExtendedAttributeKey, Object)}).
27+
*
28+
* <p>The keys are {@link ExtendedAttributeKey}s and the values are Object instances that match the
29+
* type of the provided key.
30+
*
31+
* <p>Null keys will be silently dropped.
32+
*
33+
* <p>Note: The behavior of null-valued attributes is undefined, and hence strongly discouraged.
34+
*
35+
* <p>Implementations of this interface *must* be immutable and have well-defined value-based
36+
* equals/hashCode implementations. If an implementation does not strictly conform to these
37+
* requirements, behavior of the OpenTelemetry APIs and default SDK cannot be guaranteed.
38+
*
39+
* <p>For this reason, it is strongly suggested that you use the implementation that is provided
40+
* here via the factory methods and the {@link ExtendedAttributesBuilder}.
41+
*
42+
* <p>Convenience methods are provided for translating to / from {@link Attributes}:
43+
*
44+
* <ul>
45+
* <li>{@link #asAttributes()} converts from {@link ExtendedAttributes} to {@link Attributes}
46+
* <li>{@link ExtendedAttributesBuilder#putAll(Attributes)} converts from {@link Attributes} to
47+
* {@link ExtendedAttributes}
48+
* <li>{@link #get(AttributeKey)} supports reading values using standard {@link AttributeKey}
49+
* </ul>
50+
*/
1551
@Immutable
1652
public interface ExtendedAttributes {
1753

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

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.List;
2222
import java.util.function.Predicate;
2323

24-
/** A builder of {@link Attributes} supporting an arbitrary number of key-value pairs. */
24+
/** A builder of {@link ExtendedAttributes} supporting an arbitrary number of key-value pairs. */
2525
public interface ExtendedAttributesBuilder {
2626
/** Create the {@link ExtendedAttributes} from this. */
2727
ExtendedAttributes build();
@@ -34,14 +34,14 @@ default <T> ExtendedAttributesBuilder put(AttributeKey<T> key, T value) {
3434
return put(ExtendedAttributeKey.fromAttributeKey(key), value);
3535
}
3636

37-
/** TODO. */
37+
/** Puts a {@link ExtendedAttributeKey} with associated value into this. */
3838
<T> ExtendedAttributesBuilder put(ExtendedAttributeKey<T> key, T value);
3939

4040
/**
4141
* Puts a String attribute into this.
4242
*
43-
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
44-
* your keys, if possible.
43+
* <p>Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and
44+
* pre-allocate your keys, if possible.
4545
*
4646
* @return this Builder
4747
*/
@@ -52,8 +52,8 @@ default ExtendedAttributesBuilder put(String key, String value) {
5252
/**
5353
* Puts a long attribute into this.
5454
*
55-
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
56-
* your keys, if possible.
55+
* <p>Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and
56+
* pre-allocate your keys, if possible.
5757
*
5858
* @return this Builder
5959
*/
@@ -64,8 +64,8 @@ default ExtendedAttributesBuilder put(String key, long value) {
6464
/**
6565
* Puts a double attribute into this.
6666
*
67-
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
68-
* your keys, if possible.
67+
* <p>Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and
68+
* pre-allocate your keys, if possible.
6969
*
7070
* @return this Builder
7171
*/
@@ -76,25 +76,32 @@ default ExtendedAttributesBuilder put(String key, double value) {
7676
/**
7777
* Puts a boolean attribute into this.
7878
*
79-
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
80-
* your keys, if possible.
79+
* <p>Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and
80+
* pre-allocate your keys, if possible.
8181
*
8282
* @return this Builder
8383
*/
8484
default ExtendedAttributesBuilder put(String key, boolean value) {
8585
return put(booleanKey(key), value);
8686
}
8787

88-
/** TODO. */
88+
/**
89+
* Puts a {@link ExtendedAttributes} attribute into this.
90+
*
91+
* <p>Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and
92+
* pre-allocate your keys, if possible.
93+
*
94+
* @return this Builder
95+
*/
8996
default <T> ExtendedAttributesBuilder put(String key, ExtendedAttributes value) {
90-
return put(ExtendedAttributeKey.mapKey(key), value);
97+
return put(ExtendedAttributeKey.extendedAttributesKey(key), value);
9198
}
9299

93100
/**
94101
* Puts a String array attribute into this.
95102
*
96-
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
97-
* your keys, if possible.
103+
* <p>Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and
104+
* pre-allocate your keys, if possible.
98105
*
99106
* @return this Builder
100107
*/
@@ -121,8 +128,8 @@ default <T> ExtendedAttributesBuilder put(AttributeKey<List<T>> key, T... value)
121128
/**
122129
* Puts a Long array attribute into this.
123130
*
124-
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
125-
* your keys, if possible.
131+
* <p>Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and
132+
* pre-allocate your keys, if possible.
126133
*
127134
* @return this Builder
128135
*/
@@ -136,8 +143,8 @@ default ExtendedAttributesBuilder put(String key, long... value) {
136143
/**
137144
* Puts a Double array attribute into this.
138145
*
139-
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
140-
* your keys, if possible.
146+
* <p>Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and
147+
* pre-allocate your keys, if possible.
141148
*
142149
* @return this Builder
143150
*/
@@ -151,8 +158,8 @@ default ExtendedAttributesBuilder put(String key, double... value) {
151158
/**
152159
* Puts a Boolean array attribute into this.
153160
*
154-
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
155-
* your keys, if possible.
161+
* <p>Note: It is strongly recommended to use {@link #put(ExtendedAttributeKey, Object)}, and
162+
* pre-allocate your keys, if possible.
156163
*
157164
* @return this Builder
158165
*/
@@ -163,14 +170,6 @@ default ExtendedAttributesBuilder put(String key, boolean... value) {
163170
return put(booleanArrayKey(key), toList(value));
164171
}
165172

166-
/** TODO. */
167-
default <T> ExtendedAttributesBuilder put(String key, ExtendedAttributes... value) {
168-
if (value == null) {
169-
return this;
170-
}
171-
return put(ExtendedAttributeKey.mapArrayKey(key), Arrays.asList(value));
172-
}
173-
174173
/**
175174
* Puts all the provided attributes into this Builder.
176175
*
@@ -185,7 +184,11 @@ default ExtendedAttributesBuilder putAll(Attributes attributes) {
185184
return this;
186185
}
187186

188-
/** TODO. */
187+
/**
188+
* Puts all the provided attributes into this Builder.
189+
*
190+
* @return this Builder
191+
*/
189192
@SuppressWarnings({"unchecked"})
190193
default ExtendedAttributesBuilder putAll(ExtendedAttributes attributes) {
191194
if (attributes == null) {
@@ -205,17 +208,26 @@ default <T> ExtendedAttributesBuilder remove(AttributeKey<T> key) {
205208
return remove(ExtendedAttributeKey.fromAttributeKey(key));
206209
}
207210

208-
/** TODO. */
211+
/**
212+
* Remove all attributes where {@link ExtendedAttributeKey#getKey()} and {@link
213+
* ExtendedAttributeKey#getType()} match the {@code key}.
214+
*
215+
* @return this Builder
216+
*/
209217
default <T> ExtendedAttributesBuilder remove(ExtendedAttributeKey<T> key) {
210218
if (key == null || key.getKey().isEmpty()) {
211219
return this;
212220
}
213-
// TODO:
214221
return removeIf(
215222
entryKey ->
216223
key.getKey().equals(entryKey.getKey()) && key.getType().equals(entryKey.getType()));
217224
}
218225

219-
/** TODO. */
226+
/**
227+
* Remove all attributes that satisfy the given predicate. Errors or runtime exceptions thrown by
228+
* the predicate are relayed to the caller.
229+
*
230+
* @return this Builder
231+
*/
220232
ExtendedAttributesBuilder removeIf(Predicate<ExtendedAttributeKey<?>> filter);
221233
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public static <T> ExtendedAttributeKey<T> create(
4747
return new InternalExtendedAttributeKeyImpl<>(type, key != null ? key : "");
4848
}
4949

50+
/**
51+
* Return an {@link ExtendedAttributeKey} equivalent to the {@code attributeKey}, caching entries
52+
* in {@link #ATTRIBUTE_KEY_CACHE}.
53+
*/
5054
@SuppressWarnings("unchecked")
5155
public static <T> ExtendedAttributeKey<T> fromAttributeKey(AttributeKey<T> attributeKey) {
5256
return (ExtendedAttributeKey<T>)
@@ -120,7 +124,11 @@ private static int buildHashCode(ExtendedAttributeType type, String key) {
120124
return result;
121125
}
122126

123-
/** TODO. */
127+
/**
128+
* Return the equivalent {@link AttributeKey} for the {@link ExtendedAttributeKey}, or {@code
129+
* null} if the {@link #getType()} has no equivalent {@link
130+
* io.opentelemetry.api.common.AttributeType}.
131+
*/
124132
@Nullable
125133
public static <T> AttributeKey<T> toAttributeKey(ExtendedAttributeKey<T> extendedAttributeKey) {
126134
switch (extendedAttributeKey.getType()) {
@@ -145,15 +153,14 @@ public static <T> AttributeKey<T> toAttributeKey(ExtendedAttributeKey<T> extende
145153
case DOUBLE_ARRAY:
146154
return InternalAttributeKeyImpl.create(
147155
extendedAttributeKey.getKey(), AttributeType.DOUBLE_ARRAY);
148-
case MAP:
149-
case MAP_ARRAY:
156+
case EXTENDED_ATTRIBUTES:
150157
return null;
151158
}
152159
throw new IllegalArgumentException(
153160
"Unrecognized extendedAttributeKey type: " + extendedAttributeKey.getType());
154161
}
155162

156-
/** TODO. */
163+
/** Return the equivalent {@link ExtendedAttributeKey} for the {@link AttributeKey}. */
157164
public static <T> ExtendedAttributeKey<T> toExtendedAttributeKey(AttributeKey<T> attributeKey) {
158165
switch (attributeKey.getType()) {
159166
case STRING:

0 commit comments

Comments
 (0)