Skip to content

Commit 0647b87

Browse files
committed
Review Feedback.
1 parent 464abcb commit 0647b87

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ public interface AttributesBuilder {
3636
// version.
3737
<T> AttributesBuilder put(AttributeKey<Long> key, int value);
3838

39-
/** Puts an {@link AttributeKey} with an associated value into this if the value is non-null. */
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+
*/
4043
<T> AttributesBuilder put(AttributeKey<T> key, @Nullable T value);
4144

4245
/**
43-
* Puts a String attribute into this.
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.
4448
*
4549
* <p>Note: It is strongly recommended to use {@link #put(AttributeKey, Object)}, and pre-allocate
4650
* your keys, if possible.

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

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

2021
/**
2122
* Used to construct and emit log records from a {@link Logger}.
@@ -107,16 +108,20 @@ default LogRecordBuilder setAllAttributes(Attributes attributes) {
107108
* Sets an attribute on the {@code LogRecord}. If the {@code LogRecord} previously contained a
108109
* mapping for the key, the old value is replaced by the specified value.
109110
*
111+
* <p>Note: Providing a null value is a no-op and will not remove previously set values.
112+
*
110113
* @param key the key for this attribute.
111114
* @param value the value for this attribute.
112115
* @return this.
113116
*/
114-
<T> LogRecordBuilder setAttribute(AttributeKey<T> key, T value);
117+
<T> LogRecordBuilder setAttribute(AttributeKey<T> key, @Nullable T value);
115118

116119
/**
117120
* Sets a String attribute on the {@code LogRecord}. If the {@code LogRecord} previously contained
118121
* a mapping for the key, the old value is replaced by the specified value.
119122
*
123+
* <p>Note: Providing a null value is a no-op and will not remove previously set values.
124+
*
120125
* <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and
121126
* pre-allocate your keys, if possible.
122127
*
@@ -125,7 +130,7 @@ default LogRecordBuilder setAllAttributes(Attributes attributes) {
125130
* @return this.
126131
* @since 1.48.0
127132
*/
128-
default LogRecordBuilder setAttribute(String key, String value) {
133+
default LogRecordBuilder setAttribute(String key, @Nullable String value) {
129134
return setAttribute(stringKey(key), value);
130135
}
131136

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ 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}, but not valid keys.
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.
9294
*
9395
* <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and
9496
* pre-allocate your keys, if possible.
@@ -97,7 +99,7 @@ static Span wrap(SpanContext spanContext) {
9799
* @param value the value for this attribute.
98100
* @return this.
99101
*/
100-
default Span setAttribute(String key, String value) {
102+
default Span setAttribute(String key, @Nullable String value) {
101103
return setAttribute(AttributeKey.stringKey(key), value);
102104
}
103105

@@ -150,13 +152,13 @@ default Span setAttribute(String key, boolean value) {
150152
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
151153
* the key, the old value is replaced by the specified value.
152154
*
153-
* <p>Note: the behavior of null values is undefined, and hence strongly discouraged.
155+
* <p>Note: Providing a null value is a no-op.
154156
*
155157
* @param key the key for this attribute.
156158
* @param value the value for this attribute.
157159
* @return this.
158160
*/
159-
<T> Span setAttribute(AttributeKey<T> key, T value);
161+
<T> Span setAttribute(AttributeKey<T> key, @Nullable T value);
160162

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

0 commit comments

Comments
 (0)