fix(core): avoid leaking Node.js types via otperformance#5987
Merged
pichlermarc merged 2 commits intoopen-telemetry:mainfrom Oct 8, 2025
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5987 +/- ##
==========================================
+ Coverage 95.17% 95.18% +0.01%
==========================================
Files 316 315 -1
Lines 8521 8520 -1
Branches 1763 1763
==========================================
Hits 8110 8110
+ Misses 411 410 -1
🚀 New features to boost your workflow:
|
0bcc1cc to
aad004b
Compare
Contributor
|
I've checked places where const performanceNavigationTiming = (
otperformance as unknown as Performance
).getEntriesByType?.('navigation')[0] as PerformanceEntries;Not sure how many packages might use this export directly but the remediation for any type issue is pretty straight forward. Browser instrumentations are already doing it. |
david-luna
approved these changes
Oct 7, 2025
legendecas
approved these changes
Oct 8, 2025
Member
Author
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.