fix(tracing): Better guarding for performance observer#8872
Merged
Conversation
This was referenced Aug 28, 2023
lforst
approved these changes
Aug 28, 2023
| return ( | ||
| entry.entryType === 'resource' && | ||
| 'initiatorType' in entry && | ||
| 'nextHopProtocol' in entry && |
Contributor
There was a problem hiding this comment.
l: this still doesn't guarantee that nextHopProtocol is a string - at the same time checking whether the key exists is probably enough
Member
Author
There was a problem hiding this comment.
yeah, I figured the same.. I mean these are browser APIs, I think if this exists it will be a string, this is more to make sure this is not some other type of resource... IMHO we can do
- Just check existence (current code)
- Check existence +
typeof entry.nextHopProtocol === 'string - Only check type - requires type cast (which is fine I guess)
typeof (entry as PerformanceResourceTiming).nextHopProtocol === 'string
Contributor
size-limit report 📦
|
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.
This removes a type cast for the performance observer and actually adds some guards to make sure we do not run into cases where a property we expect to exist does not exist.
It seems we sometimes ran into cases where
nextHopProtocolwould beundefined, not a string, leading to https://github.com/getsentry/sentry-javascript/blob/develop/packages/tracing-internal/src/browser/request.ts#L202 failing.I now specifically check for the existence of this property, as well as also adding a default for all the time based stuff (0) to ensure these also work in the case one of the fields does not exist (instead of checking for existence of all of them).
Closes #8870
Closes #8863