Skip to content

Commit

Permalink
Update javadoc to allow null/empty attr values (#5616)
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk authored Jul 11, 2023
1 parent a781ba8 commit 16e7113
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions api/all/src/main/java/io/opentelemetry/api/trace/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ static Span wrap(SpanContext spanContext) {
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
* the key, the old value is replaced by the specified value.
*
* <p>If a null or empty String {@code value} is passed in, the behavior is undefined, and hence
* strongly discouraged.
* <p>Empty String "" and null are valid attribute {@code value}, but not valid keys.
*
* <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and
* pre-allocate your keys, if possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,11 @@ public AttributesBuilder putAll(Attributes attributes) {
assertThatCode(() -> myAttributesBuilder.remove(stringKey("foo"))).doesNotThrowAnyException();
assertThatCode(() -> myAttributesBuilder.removeIf(unused -> false)).doesNotThrowAnyException();
}

@Test
void emptyValueIsValid() {
AttributeKey<String> key = stringKey("anything");
Attributes attributes = Attributes.of(key, "");
assertThat(attributes.get(key)).isEqualTo("");
}
}

0 comments on commit 16e7113

Please sign in to comment.