Skip to content

Conversation

@krystofwoldrich
Copy link
Contributor

@krystofwoldrich krystofwoldrich commented Jun 21, 2024

📢 Type of change

  • Bugfix

📜 Description

This PR adds necessary scope changes to enables hybrid SDKs (React Native) to synchronize their scopes to the native SDKs which are using the Hub and Scopes architecture.

The following variants were considered.

Change static RN SDK APIs to operate on Global Scope

This will cause all integration from JS Core to stop working as they do not use the RN SDK APIs.

Add Default Scope which all SDK APIs will use

This adds new scope to the mix and increases complexity.

Set Global and Isolation scope as one reference.

Due to default falls back any interaction with the static APIs before Sentry.init will break the sync. The isolation scope will be created on first call before RN setup.

Use scope change listener

Not suitable for sync as it returns whole scope, comparing diff is too expensive.

Hook into scope changes

This work with API calls before init, the date before init won't be sync the same as in the previous implementation. We patch our own object, in the future we can use listeners for individual changes.

💚 How did you test it?

sample app, unit tests

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • All tests passing
  • No breaking changes

#skip-changelog

@krystofwoldrich krystofwoldrich changed the title Kw/fix-native-scope-sync fix(scope): Use React Native Scope as isolation and global scope to fix native scope sync Jun 21, 2024
@krystofwoldrich krystofwoldrich requested a review from mydea June 21, 2024 17:14
@krystofwoldrich krystofwoldrich marked this pull request as ready for review June 24, 2024 09:35
@github-actions
Copy link
Contributor

github-actions bot commented Jun 24, 2024

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1206.38 ms 1207.23 ms 0.85 ms
Size 2.36 MiB 3.02 MiB 668.98 KiB

@github-actions
Copy link
Contributor

github-actions bot commented Jun 24, 2024

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 471.98 ms 520.76 ms 48.78 ms
Size 7.15 MiB 8.19 MiB 1.04 MiB

Copy link
Collaborator

@lucas-zimerman lucas-zimerman left a comment

Choose a reason for hiding this comment

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

I asked some minor changes, but other than that it looks good for merge, good job on the solution chosen here!

Copy link
Collaborator

@lucas-zimerman lucas-zimerman left a comment

Choose a reason for hiding this comment

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

Actually, there is one thing that is bothering me, with your implementation, doesn't it have a chance to break if users uses minification on their code? in that case, the name setTag may change but not the string literal setTag.

@lucas-zimerman lucas-zimerman self-requested a review June 24, 2024 12:58
@krystofwoldrich
Copy link
Contributor Author

I've check the minified output of the Metro bundler and it correctly recognizes the dynamic access to the properties and does not minify the scope.

__d((function(g,r,i,a,m,e,d){Object.defineProperty(e,"__esModule",{value:!0}),e.enableSyncToNative=function(n){if(t.has(n))return;t.set(n,!0),n.setUser=(0,r(d[0]).wrapFunction)(n.setUser,(function(t){return function(c){return r(d[1]).NATIVE.setUser(c),t.call(n,c)}})),n.setTag=(0,r(d[0])

We dynamically access scope properties in the core as well, so even if changed in RN the scope would not be minified.

https://github.com/getsentry/sentry-javascript/blob/874df8e5b28e2f0f530b0e651067cdd2aa3e5cf7/packages/core/src/utils/spanOnScope.ts#L28

@github-actions
Copy link
Contributor

github-actions bot commented Jun 24, 2024

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 412.04 ms 455.02 ms 42.98 ms
Size 17.73 MiB 19.92 MiB 2.18 MiB

Base automatically changed from kw/bump-js-to-8-11 to v6 June 25, 2024 09:11
Copy link
Collaborator

@lucas-zimerman lucas-zimerman left a comment

Choose a reason for hiding this comment

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

All looks good from my part. We should wait for the other reviewer before merging.

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.

this makes sense to me 👍

@krystofwoldrich krystofwoldrich changed the title fix(scope): Use React Native Scope as isolation and global scope to fix native scope sync fix(scope): Hooks into Global and Isolations Scopes for Sync with the native scope Jun 25, 2024
@krystofwoldrich krystofwoldrich merged commit 6af7578 into v6 Jun 25, 2024
@krystofwoldrich krystofwoldrich deleted the kw/fix-native-scope-sync branch June 25, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants