Skip to content

Latest commit

 

History

History
25 lines (15 loc) · 1.74 KB

README.md

File metadata and controls

25 lines (15 loc) · 1.74 KB

LazySentry

This is some code I use to lazy-load the Sentry JavaScript SDKs, including a basic lazy-loaded React ErrorBoundary. Currently, Sentry's JavaScript SDK is very large. They have built-in basic lazy loading support, however it does not work for on-premise installations, and also does not support the tight React integration via an ErrorBoundary.

Until the bundle size is reduced (as part of v7 of the SDK), lazy-loading the SDK can at least defer the cost a bit.

Files in this repo

  • LazySentryImports: The actual parts of the Sentry module that we want to use
  • LazySentry: Handles loading Sentry. If Sentry has not been loaded yet, the functions (eg. captureException) are buffered in a queue. Once the Sentry library is loaded, all the buffered calls are replayed
  • LazySentryErrorBoundary: React ErrorBoundary that handles a lazy-loaded Sentry SDK

Usage

  • Use LazySentry instead of @sentry/browser or @sentry/react in your code.
  • Call init at some appropriate time, such as after your app has loaded all its main code, or in a requestIdleCallback callback.
  • If you want to use more features from Sentry, add them to LazySentryImports then add wrappers for them in LazySentry.

Example

This code snippet is used in the Sentry initialisation code on dnstools.ws: https://github.com/Daniel15/dnstools/blob/master/src/DnsTools.Web/ClientApp/src/index.tsx. The LazySentry repo is configured as a Git submodule.

Support

There is no warranty nor any support provided for the code in this repository.