-
Notifications
You must be signed in to change notification settings - Fork 48
feat: never return undefined when the method expects an object #175
Conversation
Codecov ReportBase: 95.23% // Head: 95.39% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main open-telemetry/oteps#175 +/- ##
==========================================
+ Coverage 95.23% 95.39% +0.16%
==========================================
Files 45 45
Lines 650 651 +1
Branches 102 101 -1
==========================================
+ Hits 619 621 +2
+ Misses 31 30 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
marking with request change until the spec part is clear regarding this.
If we go this root we should not stick on getSpan
instead we should fix this for all context methods (e.g. baggage,...).
I have added this to every other public method which returned undefined (and not a string). This is way farther from my area of confidence in the JS API though. So I may have messed up. Not having this is currently forcing us into writing a lot of defensive conditions. Basically, whenever we retrieve the current span from context, we need to check if there is indeed a span, which is quite verbose. |
@@ -61,7 +61,7 @@ export interface Baggage { | |||
* | |||
* @param key The key which identifies the BaggageEntry | |||
*/ | |||
getEntry(key: string): BaggageEntry | undefined; |
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.
This removes the ability to determine if a baggage entry is present in the baggage. I'd find this line of change unexpected regarding the OP:
Whenever API call returns values that is expected to be non-null value - in case of error in processing logic
The undefined
returned here is not an error.
I don't think returning undefined is invalid.
IMO, this method is not expected to return a non-null value. The docs explicitly state that it may be undefined. Further, this spec guidance is specifically around error handling and what you've changed is the normal operation of the API. This change could also be interpreted as breaking. This package is being moved to the main https://github.com/open-telemetry/opentelemetry-js repository and I would suggest that if you feel this is an important issue you open an issue there. |
I went ahead and created a discussion issue over there open-telemetry/opentelemetry-js#3316 |
I believe returning
undefined
when the context has no span is invalid per the specification:https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/error-handling.md#guidance
See also the discussion in https://github.com/open-telemetry/oteps/issues/216
Note: this may be deemed a breaking change, in which case I am happy to rename the commit to
feat
, and to wait for the next planned appropriate release.