-
Notifications
You must be signed in to change notification settings - Fork 806
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
chore: create NoopSpan instead reusing NOOP_SPAN #1899
chore: create NoopSpan instead reusing NOOP_SPAN #1899
Conversation
Always create a fresh NoopSpan instead of returning the same NOOP_SPAN several times. Users may attach some data to a span or use it as a key in a map. Avoid issues/leaks in such cases by always returning a new NoopSpan.
Codecov Report
@@ Coverage Diff @@
## main #1899 +/- ##
==========================================
+ Coverage 92.30% 92.77% +0.46%
==========================================
Files 157 172 +15
Lines 5122 5964 +842
Branches 1089 1268 +179
==========================================
+ Hits 4728 5533 +805
- Misses 394 431 +37
|
Added the |
Suppose we had already shipped 1.0 when you thought of this. I assume that we would
|
This seems like a reasonable course of action |
The missing part is to remove it on next major. Which in turn leads to questions like how often a new major will be made and if there will be some LTS support for older majors like in e.g. node.js. But that's a bigger discussion to be done outside of this PR. But it shows once more that issues like #1765 and #1750 are needed to be handled before GA. |
Current thinking of the spec sig is "very rarely." last I heard was "years" |
Besides a major change in spec there could be JS local details causing majors. e.g. move to new typescript versions resulting in incompatibility with older ones,... de-support NodeJs 8,... But sure, I don't expect we reach v16 soon :o) |
Suggestion:
This to both explicit as it's creating a new span, but we can then hide the details within the helper and the NoopSpan class code just disappears -- further assisting minification. And size wise this becomes (could be optimized a little more)
vs the following where all of the
|
This will break instanceof checks. Not sure if anyone is using these checks at the moment but is a possibility worth considering. |
Yes, it would and I see that in the tests, if this is really required (which I would think the idea of having a Noop version assumes that code doesn't want or need to check) then a possible "workaround" would be to check whether the span.context() === INVALID_SPAN_CONTEXT |
Currently there is But I just remembered that spec tells that only a I assume this is again bad for minification but IMHO the ship to use classes,.. in OTel API has sailed. I don't think that changing Otel API is not yet GA, if proper minimizing is a major concern I recommend to start now but not on single, small classes instead rework the complete API. |
There are
|
There are not too many real classes in the API. The API singletons and the noop classes I think is it. It probably wouldn't take too much effort to change if minification is a real concern. The SDK is another matter. |
Generally, minification concerns are not a single "big" thing, but more of death by a thousand cuts, so (apart from @Flarna spec link) requiring that everyone (SDK or otherwise) use But it seems that based on the spec we need to change this anyway so that only a tracer can create a span, so choosing the name of factory method on a tracer should be consideration as the length on the name has direct affects... i.e. But to be spec compliant, it would seem that this functionality should be moved and (ideally) the NoopSpan class removed or not exported at least from the API. As a workaround it is possible that if a particularity method is called multiple times in a block using a local variable can help -- I don't see that in this case though. |
I looked once a again into this and it seems it's not that straight forward to solve this. There is a place where using
But as this is inside API it's possible to keep using |
Update the PR to use But not sure if we should really go this path. |
Remove NoopSpan from API and use NOOP_TRACER.startSpan() to create them. Remove NoRecordingSpan and replace creation of them by NOOP_TRACER.startSpan().
The prohibition on creating spans without a tracer applies primarily to users. Internally we can do what we think makes sense as long as it isn't leaked to the user. IMO we shouldn't export the NoopSpan from the API at all |
I looks like we are only using NoopSpan from within the API (exception is the ot-tracing\test\Tracer.test.ts) so we could do the above and simple NOT export the NoopSpan from the Api -- thus making it private (in theory anyway) and the Api would be "compliant" from a users perspective (for NoopSpan) |
NoopSpan is also used in the http plugin it looks like at least. This should probably be |
I removed all usages of |
@open-telemetry/javascript-maintainers @open-telemetry/javascript-approvers please review PRs that affect the API. I want to merge what we have so I can move the code to the API repository this week. |
You closed the PR but this PR doesn't stop instrumentation right ? I think that was the goal with the non-recording span |
|
Always create a fresh
NoopSpan
instead of returning the sameNOOP_SPAN
several times.Users may attach some data to a span or use it as a key in a map.
Avoid issues/leaks in such cases by always returning a new
NoopSpan
.