sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

ref(core): Use versioned carrier on global object

Open Lms24 opened this issue 1 year ago • 4 comments

This PR implements a versioned Sentry carrier as described in #12188. The idea is that SDKs can from now on access their global Sentry instance and thereby no longer overwrite or interfere with potentially other SDKs (e.g. 3rd party libraries, scripts, etc).

Internally, SDKs can access their carrier via the window.__SENTRY__[SDK_VERSION]. Externally (spotlight, loader script) via window.__SENTRY__[window.__SENTRY__.version].

image

As we can see in this example, the main SDK sets its properties on the 8.4.0 key, while another, presumably older SDK sets its hub directly onto the __SENTRY__ object.

There are some caveats to consider with this approach as documented in #12188 so I'd be happy to get some feedback from reviewers. However, I wonder if the benefits (i.e. get rid of a lot of errors our users can't do much about) outweigh the potential problems.

closes #12188

also:

fixes https://github.com/getsentry/sentry-javascript/issues/12155 fixes https://github.com/getsentry/sentry-javascript/issues/12054

If we go through with this, we have to make updates to:

  • Spotlight, to access versioned carrier
  • The loader script to access the versioned carrier
    • I temporarily patched the loader script we use in our loader integration tests to highlight the necessary change and to get the tests passing.

Lms24 avatar May 24 '24 09:05 Lms24

size-limit report 📦

Path Size
@sentry/browser 21.74 KB (-0.2% 🔽)
@sentry/browser (incl. Tracing) 32.75 KB (-0.14% 🔽)
@sentry/browser (incl. Tracing, Replay) 68.21 KB (-0.11% 🔽)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 61.63 KB (-0.12% 🔽)
@sentry/browser (incl. Tracing, Replay with Canvas) 72.25 KB (-0.11% 🔽)
@sentry/browser (incl. Tracing, Replay, Feedback) 84.32 KB (-0.08% 🔽)
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 85.78 KB (-0.09% 🔽)
@sentry/browser (incl. metrics) 23.12 KB (-0.21% 🔽)
@sentry/browser (incl. Feedback) 37.74 KB (-0.15% 🔽)
@sentry/browser (incl. sendFeedback) 26.31 KB (-0.17% 🔽)
@sentry/browser (incl. FeedbackAsync) 30.74 KB (-0.17% 🔽)
@sentry/react 24.46 KB (-0.17% 🔽)
@sentry/react (incl. Tracing) 35.78 KB (-0.14% 🔽)
@sentry/vue 25.71 KB (-0.17% 🔽)
@sentry/vue (incl. Tracing) 34.58 KB (-0.11% 🔽)
@sentry/svelte 21.87 KB (-0.23% 🔽)
CDN Bundle 22.97 KB (-0.15% 🔽)
CDN Bundle (incl. Tracing) 34.25 KB (-0.11% 🔽)
CDN Bundle (incl. Tracing, Replay) 68.07 KB (-0.04% 🔽)
CDN Bundle (incl. Tracing, Replay, Feedback) 73.08 KB (-0.05% 🔽)
CDN Bundle - uncompressed 67.8 KB (-0.12% 🔽)
CDN Bundle (incl. Tracing) - uncompressed 101.67 KB (-0.08% 🔽)
CDN Bundle (incl. Tracing, Replay) - uncompressed 211.56 KB (-0.04% 🔽)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 223.94 KB (-0.04% 🔽)
@sentry/nextjs (client) 35.12 KB (-0.1% 🔽)
@sentry/sveltekit (client) 33.37 KB (-0.09% 🔽)
@sentry/node 114.66 KB (-0.04% 🔽)
@sentry/aws-serverless 103.37 KB (-0.01% 🔽)

github-actions[bot] avatar May 24 '24 09:05 github-actions[bot]

Hmm seems like TS 3.8 isn't happy with the VersionString type alias being used in a [key: VersionString]: SentryCarrier type 😢 https://github.com/getsentry/sentry-javascript/actions/runs/9222664236/job/25374684416?pr=12206#step:11:109

Problem is, I can't use [key: string]: SentryCarrier either because it conflicts with other properties

Lms24 avatar May 24 '24 12:05 Lms24

@timfish @krystofwoldrich do you see potential problems with this in Electron or RN?

Lms24 avatar May 24 '24 14:05 Lms24

@timfish @krystofwoldrich do you see potential problems with this in Electron or RN?

No!

timfish avatar May 24 '24 14:05 timfish

@timfish @krystofwoldrich do you see potential problems with this in Electron or RN?

Nope, I don't see problems with this in RN.

krystofwoldrich avatar May 28 '24 12:05 krystofwoldrich