-
Notifications
You must be signed in to change notification settings - Fork 915
Update Attributes API to comply the spec #1437
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 Attributes API to comply the spec #1437
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1437 +/- ##
============================================
- Coverage 91.39% 91.37% -0.03%
Complexity 954 954
============================================
Files 116 116
Lines 3416 3431 +15
Branches 281 290 +9
============================================
+ Hits 3122 3135 +13
- Misses 205 206 +1
- Partials 89 90 +1
Continue to review full report at Codecov.
|
anuraaga
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we just not set null in Attributes instead of filtering on consumption?
"Attribute values of null are considered to be not set and get discarded as if that SetAttribute call had never been made"
Since anyone can create a Resource, even outside of this codebase, we wouldn't be able to control that, so having the filter in place seems like a good idea. But, yes, "don't do that" is always a good rule when it comes to nulls. ;) |
|
@jkwatson Sorry wasn't clear, I meant filtering out null values when creating attributes, e.g. the builder's setters |
|
@anuraaga |
|
Hmm if we use null as an implementation detail of emptiness it's ok. In that case shouldn't |
|
On second thought, do we have an API for deleting attributes? |
|
Yes we do have it https://github.com/open-telemetry/opentelemetry-java/blob/master/sdk/src/main/java/io/opentelemetry/sdk/trace/RecordEventsReadableSpan.java#L314 |
I don't think events and links need to support this. they are created immutable (or lazily so), so you won't be removing attributes from existing links or events. |
|
Note: the way that attributes are deleted from spans is pretty hacky at the moment (it involves using an extension of HashMap). I'd love to figure out a better way to do it. |
| if (value.getType() == AttributeValue.Type.STRING && value.getStringValue() == null) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why other values like null array is not removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think along these lines, if we're using null to model deletion, we should just store null directly, not an attribute value with a value of null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because null values inside arrays are meaningful. Since the Attributes API does not create null attributes, it cannot exist a null value but only a value that contains an AttributeValue with null. Does it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it does not make sense. What if the "array" is null, not the value inside the array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "array" cannot be null. Resource uses the Attributes class for storing attributes which creates always an object for arrays: https://github.com/open-telemetry/opentelemetry-java/blob/master/api/src/main/java/io/opentelemetry/common/Attributes.java#L204
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very strange behavior for arrays then:
opentelemetry-java/api/src/main/java/io/opentelemetry/common/AttributeValue.java
Line 331 in 78ed649
| if (stringValues == null) { |
We replace with empty array/list.... Not too much consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General Java guidelines are to never return null for a collection, but use an empty one (per Josh Bloch in Effective Java). So, I think this behavior is a good one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed about this. It is not we return null, it is we get null and add an entry with empty collection, why then not add an entry with empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have uniformed the handling of null in 18e3719. The following cases are dropped (or removed if the key was already present):
- null strings, e.g.
(String) null - new arrays with 0 length, e.g.
new String[0] - null arrays, e.g.
(String[]) null
Instead, the following are stored as attributes:
- Empty strings
- Arrays with null values as members, e.g.
new String[] {null}
|
So assuming we do need to keep null values to model deletion (seems a bit weird if we support deletion we could have an explicit deletion API? Java |
Really? We'd still be setting the attribute with |
|
I was missing something 😅 |
387ce57 to
18e3719
Compare
This is only for the Resource, not for Span attributes. @thisthat can you update the PR title to reflect that it's just for Resource attributes? |
|
Thanks for bearing with my confusion! |
98372f3 to
2bdb1cf
Compare
|
@open-telemetry/java-approvers I have update the PR to implement the latest specification introduced by open-telemetry/opentelemetry-specification#777
|
anuraaga
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the update! I think it's ok now, but for the future, when making such a large change to a PR it may be better to close the old one and start a new one to give everyone a clean slate.
anuraaga
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
sdk/src/main/java/io/opentelemetry/sdk/trace/RecordEventsReadableSpan.java
Outdated
Show resolved
Hide resolved
jkwatson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sticking with this one!
Update attributes API to the latest spec: open-telemetry/opentelemetry-specification#777