Dynamically Loading the Sentry SDK #7886
AbhiPrasad
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As we start hitting more and more goals with our 2023 Roadmap, I wanted to spend some time taking a look the last item on that list, dynamically loading the SDK.
We've already done some work toward this by expanding our loader snippet, but I believe by leveraging build time flags + our unplugin setup we can introduce this by default to all of our NPM packages.
This probably requires breaking changes, but but I think we can find a way to do it backwards compat.
At it's core the Sentry SDK is an event processing pipeline. It takes some language/library primatives (js errors, timestamps/durations, rrweb data, etc.), applies transforms to that data, and then sends that data to a sentry instance.
This represents our three stages of the SDK
Generally we can say that all processing/transport functionalities can be asynchronously loaded - there's no need for this to be blocking in any way. Collection is where this gets tricky, since some of this needs to be registered asap so we can even collect the necessary primitives. Collection also has an added nuance for performance monitoring/distributed tracing, where we need monkeypatch xhr/fetch to attach tracing headers. Ideally this happens as soon as possible, so we get headers attached to every single outgoing request.
The current mechanisms to add functionality to the Sentry SDK are integrations. When looking at our Sentry integrations, we can see that the often mix responsibilities between collection (monkey patching stuff to get data) and processing (via our event processors API).
So we need to two things
a) for things that are obvious to code split, we need to dynamically import them. Ideally the SDK provides a good way to do this. I'm also ok to say that the only way this works is if you are also using our bundler plugin.
Quick idea - we control this again by injecting things via dumb replace plugin?
b) add a base (loader-like) impl that does data collection until the real SDK loads in
This way when you call
Sentry.init
there's at least some stuff happening - and then the actual sdk can initialize when it's needed.This discussion mostly exists as an open area to throw around ideas and experiment - any feedback/suggestions welcome!
Beta Was this translation helpful? Give feedback.
All reactions