Skip to content

feat: Expose prio scope functions #2092

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

Merged
merged 8 commits into from
May 31, 2019
Merged

feat: Expose prio scope functions #2092

merged 8 commits into from
May 31, 2019

Conversation

HazAT
Copy link
Member

@HazAT HazAT commented May 29, 2019

Counterpart to #2091

This exposes a new "global" functions from the Scope to provide a simpler API:

This enables users to do something like this:

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

// vs. 

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

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.setTags({a: 'b'});
  • This should provide users an easier path to migrate their old SDK codebase to the new one: string replace:
Raven.setTagsContext({a: 'b'}); 
// ->
Sentry.setTags({a: 'b'});

setXXX 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 setXXX.

@HazAT HazAT requested a review from kamilogorek as a code owner May 29, 2019 14:16
@HazAT HazAT self-assigned this May 29, 2019
@HazAT HazAT mentioned this pull request May 29, 2019
/**
* @inheritDoc
*/
public setExtras(extras: { [key: string]: any }): void {
Copy link
Member

Choose a reason for hiding this comment

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

isnt this setExtra? and extra?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, before we only had setExtra on the scope which allowed only key:value setExtras allowed to set an object.

I will change that it accepts both.

Copy link
Member

Choose a reason for hiding this comment

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

👍 i think its fine though i would probably want to override the entire extra per old functionality (for other things folks should probably just use setContext)

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe, we should even consider not even exposing setExtra at all anymore.
Could be too early tho, I mean it's still there in configureScope but not on Sentry.set...

Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot have multiple input types in Go, so I'd still need to have 2 methods for it

@getsentry-bot
Copy link
Contributor

getsentry-bot commented May 31, 2019

Messages
📖 ✅ TSLint passed
📖

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

Generated by 🚫 dangerJS against 25c7558

Copy link
Contributor

@kamilogorek kamilogorek left a comment

Choose a reason for hiding this comment

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

Looks good. The only change that I'd like to make in this PR as well is remove client guard from configureScope, as it's not client dependent. Once it's added, feel free to merge.

@HazAT HazAT merged commit b76b28d into master May 31, 2019
@HazAT HazAT deleted the feat/prio-scope-functions branch May 31, 2019 12:29
@G-Rath
Copy link

G-Rath commented Jun 4, 2019

Don't mean to hijack, but:

configureScope works differently in a way that in case there is no active client on the hub

When would you not have an active client? I'm guessing maybe if you don't provide a DSN value? (which is the official way to handle enabling & disabling Sentry between environments, such as for local development, iirc).

Might be useful to note that in the documentation somewhere, if it's not already (not that I think people should be encouraged to make expensive/complex operations for Sentry data if they can avoid it 😂)

(Also, I think you might have forgotten about exposing clearScope 😉 )

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.

5 participants