Skip to content

ref(replay): Extract worker into @sentry-internal/replay-worker #6665

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

Closed
wants to merge 2 commits into from

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 5, 2023

Currently, we have multiple rollup jobs in @sentry/replay, one for the worker (which is needed even at dev time), and one for the actual replay package. This is not ideal and leads to the build behaving differently from other packages.

This PR extracts the worker into a @sentry-internal/replay-worker package, which is private (=not published to NPM). It builds a single file, which is the worker in string form (plus a type file). Then, in @sentry/replay we can simply consume this package.

The main downside is that we have another package, but I believe that it is worth it for clarity in this case.

I have checked e.g. the @sentry-internal/node-integration-tests package as comparison, and it seems I don't need to do anything but set private: true in package.json to ensure we do not publish this anywhere? Let me know if that's not correct 😅

Closes #6371

@mydea mydea added the Package: replay Issues related to the Sentry Replay SDK label Jan 5, 2023
@mydea mydea requested review from billyvg, lforst and Lms24 January 5, 2023 12:56
@mydea mydea self-assigned this Jan 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.84 KB (-0.01% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 61.45 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.62 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 54.99 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.39 KB (0%)
@sentry/browser - Webpack (minified) 66.63 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.41 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.66 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.82 KB (+0.02% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.25 KB (-0.01% 🔽)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 42.99 KB (-0.01% 🔽)
@sentry/replay - Webpack (gzipped + minified) 38.24 KB (0%)

@lforst
Copy link
Contributor

lforst commented Jan 5, 2023

Instead of creating an entirely new package could we instead clean this worker thing up as a whole?:

  • Not putting the worker in a string but let it be a real and exported function.
  • Importing the function and doing toString (sorta like they're doing here)

@mydea
Copy link
Member Author

mydea commented Jan 5, 2023

Instead of creating an entirely new package could we instead clean this worker thing up as a whole?:

  • Not putting the worker in a string but let it be a real and exported function.
  • Importing the function and doing toString (sorta like they're doing here)

The problem with that is that we need the function to be transpiled, as it will be loaded as-is.

I've explored ways to make it work with actually importing the module (not as a string), but so far found no way to make this work with jsdom, sadly :( I'll give it another try, we changed a few build things, but my hopes are slim.

@billyvg
Copy link
Member

billyvg commented Jan 5, 2023

Note that we may even want to publish this to the CDN so that we can load the worker from a remote url. We have users that cannot use the worker due to CSP (can't load blobs).

@mydea
Copy link
Member Author

mydea commented Jan 5, 2023

Note that we may even want to publish this to the CDN so that we can load the worker from a remote url. We have users that cannot use the worker due to CSP (can't load blobs).

Yeah, that's also a thought I had, but this will also probably not be OK for other users (who do not want/can load stuff from external URLs outside of their direct control). So this would need to be an opt-in thing, I guess.

FYI I've also explored various other ways to inline workers with rollup, but none of them worked so far (the nice ones are esm only, and do not support cjs. others are not supported by jest/jsdom, ...)

@billyvg
Copy link
Member

billyvg commented Jan 5, 2023

Yeah, that's also a thought I had, but this will also probably not be OK for other users (who do not want/can load stuff from external URLs outside of their direct control). So this would need to be an opt-in thing, I guess.

Yeah I think opt-in, but I think users would be willing to allow our CDN host sooner than allowing blobs.

@billyvg
Copy link
Member

billyvg commented Jan 11, 2023

I'm 👍 on merging this -- currently we don't have automation to ensure that our worker bundle is not stale. If you modify the worker, you would need to build and commit the worker bundle.

@mydea
Copy link
Member Author

mydea commented Feb 10, 2023

Closes in favor of #7139

@mydea mydea closed this Feb 10, 2023
@mydea mydea deleted the fn/replay-worker branch May 2, 2023 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: replay Issues related to the Sentry Replay SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve worker build for replays
3 participants