Skip to content

feat: Add getScope #2091

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 1 commit into from
Closed

feat: Add getScope #2091

wants to merge 1 commit into from

Conversation

HazAT
Copy link
Member

@HazAT HazAT commented May 29, 2019

This exposes a new "global" function called getScope

This enables users to do something like this:

Sentry.getScope().setTags({a: 'b'});
Sentry.getScope().setContext('os', {name: 'mac'});

// vs. 

Sentry.configureScope(scope => {
  scope.setTags({a: 'b'});
  scope.setContext('os', {name: 'mac'});
});

It returns an empty Scope in case there is no current hub.

The motivation for this change is:

  • Users don't need to fully understand the concept of a scope for the simplest use case there is e.g: setting tags Sentry.getScope().setTags({a: 'b'});
  • Exposing all scope functions globally like Sentry.setTag, Sentry.setContext ... increases bundle size significantly and is way harder to maintain since we would always need to sync global API with scope API (thinking about moving towards tracing API), Sentry.getScope() is a good compromise
  • This should provide users an easier path to migrate their old SDK codebase to the new one: string replace:
Raven.setTagsContext({a: 'b'}); 
// ->
Sentry.getScope().setTags({a: 'b'});

getScope vs. configureScope

configureScope works differently in a way that in case there is no active client on the hub, the configureScope callback will not be invoked at all, meaning if there are expensive operations this is better than getScope. This is the main difference between these two functions.

@HazAT HazAT requested a review from kamilogorek as a code owner May 29, 2019 06:59
@HazAT HazAT self-assigned this May 29, 2019
@getsentry-bot
Copy link
Contributor

Messages
📖 ✅ TSLint passed
📖

@sentry/browser bundle gzip'ed minified size: (ES6: 14.6299 kB) (ES5: 15.3955 kB)

Generated by 🚫 dangerJS against 90696ea

@dcramer
Copy link
Member

dcramer commented May 29, 2019

We chatted on Slack - plan is to implement the methods directly on the top level class (vs using getScope) and define these as the consumer API for SDKs (so same as Raven -> Sentry.setUser, Sentry.setContext).

@HazAT
Copy link
Member Author

HazAT commented May 29, 2019

Closing this in favor of #2092

@HazAT HazAT closed this May 29, 2019
@HazAT HazAT deleted the feat/getScope branch May 29, 2019 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants