Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update javadoc to allow null/empty attr values #5616

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("");
}
}