Skip to content
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

fix(tracing): Better guarding for performance observer #8872

Merged
merged 1 commit into from
Aug 28, 2023
Merged

Conversation

mydea
Copy link
Member

@mydea mydea commented Aug 28, 2023

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 nextHopProtocol would be undefined, 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

return (
entry.entryType === 'resource' &&
'initiatorType' in entry &&
'nextHopProtocol' in entry &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: this still doesn't guarantee that nextHopProtocol is a string - at the same time checking whether the key exists is probably enough

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Just check existence (current code)
  2. Check existence + typeof entry.nextHopProtocol === 'string
  3. Only check type - requires type cast (which is fine I guess) typeof (entry as PerformanceResourceTiming).nextHopProtocol === 'string

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind either way

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@github-actions
Copy link
Contributor

github-actions bot commented Aug 28, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 75.22 KB (+0.05% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.2 KB (+0.11% 🔺)
@sentry/browser - Webpack (gzipped) 21.85 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 69.75 KB (+0.05% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 28.21 KB (+0.12% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 20.18 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 220.06 KB (+0.05% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 84.89 KB (+0.13% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 59.86 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.1 KB (+0.21% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 75.24 KB (+0.05% 🔺)
@sentry/react - Webpack (gzipped) 21.88 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 93.04 KB (+0.02% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 50.73 KB (+0.07% 🔺)

@mydea mydea merged commit 891a44e into develop Aug 28, 2023
78 checks passed
@mydea mydea deleted the fn/guard-check branch August 28, 2023 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants