Skip to content

Commit 1fea8b7

Browse files
committed
Revert "Clarify that AttributesBuilder.put allows nulls (#7271)"
This reverts commit d13f04d.
1 parent cc7d085 commit 1fea8b7

File tree

14 files changed

+25
-44
lines changed

14 files changed

+25
-44
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Arrays;
1010
import java.util.List;
1111
import java.util.function.Predicate;
12-
import javax.annotation.Nullable;
1312

1413
class ArrayBackedAttributesBuilder implements AttributesBuilder {
1514
private final List<Object> data;
@@ -38,7 +37,7 @@ public <T> AttributesBuilder put(AttributeKey<Long> key, int value) {
3837
}
3938

4039
@Override
41-
public <T> AttributesBuilder put(AttributeKey<T> key, @Nullable T value) {
40+
public <T> AttributesBuilder put(AttributeKey<T> key, T value) {
4241
if (key == null || key.getKey().isEmpty() || value == null) {
4342
return this;
4443
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Arrays;
1919
import java.util.List;
2020
import java.util.function.Predicate;
21-
import javax.annotation.Nullable;
2221

2322
/** A builder of {@link Attributes} supporting an arbitrary number of key-value pairs. */
2423
public interface AttributesBuilder {
@@ -36,22 +35,18 @@ public interface AttributesBuilder {
3635
// version.
3736
<T> AttributesBuilder put(AttributeKey<Long> key, int value);
3837

39-
/**
40-
* Puts an {@link AttributeKey} with an associated value into this if the value is non-null.
41-
* Providing a null value does not remove or unset previously set values.
42-
*/
43-
<T> AttributesBuilder put(AttributeKey<T> key, @Nullable T value);
38+
/** Puts a {@link AttributeKey} with associated value into this. */
39+
<T> AttributesBuilder put(AttributeKey<T> key, T value);
4440

4541
/**
46-
* Puts a String attribute into this if the value is non-null. Providing a null value does not
47-
* remove or unset previously set values.
42+
* Puts a String attribute into this.
4843
*
4944
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
5045
* your keys, if possible.
5146
*
5247
* @return this Builder
5348
*/
54-
default AttributesBuilder put(String key, @Nullable String value) {
49+
default AttributesBuilder put(String key, String value) {
5550
return put(stringKey(key), value);
5651
}
5752

api/all/src/main/java/io/opentelemetry/api/logs/DefaultLogger.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import io.opentelemetry.context.Context;
1111
import java.time.Instant;
1212
import java.util.concurrent.TimeUnit;
13-
import javax.annotation.Nullable;
1413

1514
class DefaultLogger implements Logger {
1615

@@ -78,7 +77,7 @@ public LogRecordBuilder setBody(Value<?> body) {
7877
}
7978

8079
@Override
81-
public <T> LogRecordBuilder setAttribute(AttributeKey<T> key, @Nullable T value) {
80+
public <T> LogRecordBuilder setAttribute(AttributeKey<T> key, T value) {
8281
return this;
8382
}
8483

api/all/src/main/java/io/opentelemetry/api/logs/LogRecordBuilder.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import io.opentelemetry.context.Context;
1717
import java.time.Instant;
1818
import java.util.concurrent.TimeUnit;
19-
import javax.annotation.Nullable;
2019

2120
/**
2221
* Used to construct and emit log records from a {@link Logger}.
@@ -108,20 +107,16 @@ default LogRecordBuilder setAllAttributes(Attributes attributes) {
108107
* Sets an attribute on the {@code LogRecord}. If the {@code LogRecord} previously contained a
109108
* mapping for the key, the old value is replaced by the specified value.
110109
*
111-
* <p>Note: Providing a null value is a no-op and will not remove previously set values.
112-
*
113110
* @param key the key for this attribute.
114111
* @param value the value for this attribute.
115112
* @return this.
116113
*/
117-
<T> LogRecordBuilder setAttribute(AttributeKey<T> key, @Nullable T value);
114+
<T> LogRecordBuilder setAttribute(AttributeKey<T> key, T value);
118115

119116
/**
120117
* Sets a String attribute on the {@code LogRecord}. If the {@code LogRecord} previously contained
121118
* a mapping for the key, the old value is replaced by the specified value.
122119
*
123-
* <p>Note: Providing a null value is a no-op and will not remove previously set values.
124-
*
125120
* <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and
126121
* pre-allocate your keys, if possible.
127122
*
@@ -130,7 +125,7 @@ default LogRecordBuilder setAllAttributes(Attributes attributes) {
130125
* @return this.
131126
* @since 1.48.0
132127
*/
133-
default LogRecordBuilder setAttribute(String key, @Nullable String value) {
128+
default LogRecordBuilder setAttribute(String key, String value) {
134129
return setAttribute(stringKey(key), value);
135130
}
136131

api/all/src/main/java/io/opentelemetry/api/trace/PropagatedSpan.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.opentelemetry.api.common.AttributeKey;
99
import io.opentelemetry.api.common.Attributes;
1010
import java.util.concurrent.TimeUnit;
11-
import javax.annotation.Nullable;
1211
import javax.annotation.concurrent.Immutable;
1312

1413
/**
@@ -43,7 +42,7 @@ private PropagatedSpan(SpanContext spanContext) {
4342
}
4443

4544
@Override
46-
public Span setAttribute(String key, @Nullable String value) {
45+
public Span setAttribute(String key, String value) {
4746
return this;
4847
}
4948

@@ -63,7 +62,7 @@ public Span setAttribute(String key, boolean value) {
6362
}
6463

6564
@Override
66-
public <T> Span setAttribute(AttributeKey<T> key, @Nullable T value) {
65+
public <T> Span setAttribute(AttributeKey<T> key, T value) {
6766
return this;
6867
}
6968

api/all/src/main/java/io/opentelemetry/api/trace/Span.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ static Span wrap(SpanContext spanContext) {
8888
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
8989
* the key, the old value is replaced by the specified value.
9090
*
91-
* <p>Empty String "" and null are valid attribute {@code value}s, but not valid keys.
92-
*
93-
* <p>Note: Providing a null value is a no-op and will not remove previously set values.
91+
* <p>Empty String "" and null are valid attribute {@code value}, but not valid keys.
9492
*
9593
* <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and
9694
* pre-allocate your keys, if possible.
@@ -99,7 +97,7 @@ static Span wrap(SpanContext spanContext) {
9997
* @param value the value for this attribute.
10098
* @return this.
10199
*/
102-
default Span setAttribute(String key, @Nullable String value) {
100+
default Span setAttribute(String key, String value) {
103101
return setAttribute(AttributeKey.stringKey(key), value);
104102
}
105103

@@ -152,13 +150,13 @@ default Span setAttribute(String key, boolean value) {
152150
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
153151
* the key, the old value is replaced by the specified value.
154152
*
155-
* <p>Note: Providing a null value is a no-op.
153+
* <p>Note: the behavior of null values is undefined, and hence strongly discouraged.
156154
*
157155
* @param key the key for this attribute.
158156
* @param value the value for this attribute.
159157
* @return this.
160158
*/
161-
<T> Span setAttribute(AttributeKey<T> key, @Nullable T value);
159+
<T> Span setAttribute(AttributeKey<T> key, T value);
162160

163161
/**
164162
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for

api/all/src/test/java/io/opentelemetry/api/common/AttributesTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Map;
2727
import java.util.NoSuchElementException;
2828
import java.util.concurrent.atomic.AtomicBoolean;
29-
import javax.annotation.Nullable;
3029
import org.junit.jupiter.api.Test;
3130

3231
/** Unit tests for {@link Attributes}s. */
@@ -566,7 +565,7 @@ public <T> AttributesBuilder put(AttributeKey<Long> key, int value) {
566565
}
567566

568567
@Override
569-
public <T> AttributesBuilder put(AttributeKey<T> key, @Nullable T value) {
568+
public <T> AttributesBuilder put(AttributeKey<T> key, T value) {
570569
return null;
571570
}
572571

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import io.opentelemetry.context.Context;
1414
import java.time.Instant;
1515
import java.util.concurrent.TimeUnit;
16-
import javax.annotation.Nullable;
1716

1817
class ExtendedDefaultLogger implements ExtendedLogger {
1918

@@ -52,7 +51,7 @@ public <T> ExtendedLogRecordBuilder setAttribute(ExtendedAttributeKey<T> key, T
5251
}
5352

5453
@Override
55-
public <T> ExtendedLogRecordBuilder setAttribute(AttributeKey<T> key, @Nullable T value) {
54+
public <T> ExtendedLogRecordBuilder setAttribute(AttributeKey<T> key, T value) {
5655
return this;
5756
}
5857

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.opentelemetry.context.Context;
1616
import java.time.Instant;
1717
import java.util.concurrent.TimeUnit;
18-
import javax.annotation.Nullable;
1918

2019
/** Extended {@link LogRecordBuilder} with experimental APIs. */
2120
public interface ExtendedLogRecordBuilder extends LogRecordBuilder {
@@ -120,7 +119,7 @@ default ExtendedLogRecordBuilder setAllAttributes(ExtendedAttributes attributes)
120119
* attribute APIs.
121120
*/
122121
@Override
123-
<T> ExtendedLogRecordBuilder setAttribute(AttributeKey<T> key, @Nullable T value);
122+
<T> ExtendedLogRecordBuilder setAttribute(AttributeKey<T> key, T value);
124123

125124
/**
126125
* Set an attribute.

opencensus-shim/src/main/java/io/opentelemetry/opencensusshim/DelegatingSpan.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.opentelemetry.context.Scope;
1616
import java.time.Instant;
1717
import java.util.concurrent.TimeUnit;
18-
import javax.annotation.Nullable;
1918

2019
/**
2120
* Delegates <i>all</i> {@link Span} methods to some underlying Span via {@link
@@ -53,12 +52,12 @@ default boolean isRecording() {
5352
}
5453

5554
@Override
56-
default <T> Span setAttribute(AttributeKey<T> key, @Nullable T value) {
55+
default <T> Span setAttribute(AttributeKey<T> key, T value) {
5756
return getDelegate().setAttribute(key, value);
5857
}
5958

6059
@Override
61-
default Span setAttribute(String key, @Nullable String value) {
60+
default Span setAttribute(String key, String value) {
6261
return getDelegate().setAttribute(key, value);
6362
}
6463

0 commit comments

Comments
 (0)