fix(core): avoid leaking Node.js types via otperformance #5987
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Which problem is this PR solving?
See #5916
This is the likely more controversial fix (see #5986 for Part I).
otperformanceexported from@opentelemetry/coreis leaking Node.js' types even when the project it is used in is not Node.js-based.The problem here is that the type-defintion is overly broad for what it represents (has Node.js extensions that don't exist in the browser). In our code-base essentially only
now()andtimeOriginare used without casting the type. My proposal is to use{ now(): number; readonly timeOrigin: number}as a replacement. This will narrow down the type to a safe minimal API, but it will technically be breaking.I assume though, that since
otperformancetechnically breaking folks that use it in that way is - if anything - a heads-up that there may be a bug in their code too.
In the past, I've occasionally mentioned SemVer TS (a TypeScript-specific variant of SemVer) as the basis for some of my decisions as I feel like it explains many TypeScript versioning caveats very well. It seems to support the sentiment that this sort of change would be acceptable too:
The spec then continues with:
Changing the runtime behavior to match the types would in our case mean that we'll have to essentially polyfill any Node.js extensions there are, which IMO may just lead to more type-level bugs down the line that need fixing.