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(replay): Only call scope.getLastBreadcrumb if available #6969

Merged
merged 2 commits into from
Jan 30, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Jan 30, 2023

Scope.getLastBreadcrumb was introduced quite recently for replay and it generally works fine. Just in the few edge cases, where the base SDK version can't be changed or multiple hubs cause conflicts, Replay will crash when the method is not available on the passed scope. This PR lets handleScope early-return null in case the getLastBreadcrumb method does not exist. This will lead to missing breadcrumbs in the replay but at least it will avoid a crash.

closes #6542

@Lms24 Lms24 requested review from mydea and billyvg January 30, 2023 07:47
@@ -26,6 +26,10 @@ export const handleScopeListener: (replay: ReplayContainer) => (scope: Scope) =>
* An event handler to handle scope changes.
*/
export function handleScope(scope: Scope): Breadcrumb | null {
if (typeof scope.getLastBreadcrumb !== 'function') {
Copy link

@m-nathani m-nathani Jan 30, 2023

Choose a reason for hiding this comment

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

LGTM. 👍🏼

I wish i would have created this PR before 🤦🏼 🥼

Copy link
Member Author

Choose a reason for hiding this comment

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

According to this methods signature, scope is always defined; so no need to guard against it being undefined ;)
Furthermore, this is where we call the function that ends up calling handleScope. As you can see, it is guarded by the scope being defined there:

scope.addScopeListener(handleScopeListener(replay));

Choose a reason for hiding this comment

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

awesome sauce... 🆒 . The guarded scope looks good ⚡

Copy link
Member

Choose a reason for hiding this comment

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

l: I would just do if (scope.getLastBreadcrumb), saves some bytes and should be good enough here!

Copy link
Member Author

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.85 KB (0%)
@sentry/browser - ES5 CDN Bundle (minified) 61.55 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.52 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 54.85 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.24 KB (0%)
@sentry/browser - Webpack (minified) 66.25 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.27 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.56 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.77 KB (0%)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.06 KB (0%)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 43.71 KB (+0.02% 🔺)
@sentry/replay - Webpack (gzipped + minified) 38.46 KB (+0.02% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 61.04 KB (+0.01% 🔺)

@Lms24 Lms24 self-assigned this Jan 30, 2023
Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

👍 LGTM! For reference, let's do this fix, with the conscious decision that if such things keep popping up, we'll not commit to work around all of them. 🚀

@Lms24 Lms24 merged commit 50817ac into master Jan 30, 2023
@Lms24 Lms24 deleted the lms-guard-getlastbreadcrumb branch January 30, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

e.getLastBreadcrumb is not a function. (In 'e.getLastBreadcrumb()', 'e.getLastBreadcrumb' is undefined)
3 participants