feat: Explicit Scope for captureException and captureMessage#2627
feat: Explicit Scope for captureException and captureMessage#2627kamilogorek merged 4 commits intomasterfrom
Conversation
HazAT
left a comment
There was a problem hiding this comment.
While I really appreciate the PR description maybe let's add a few sentences about the motivation and link issues. Also, let's link the notion doc that will soon move to develop.sentry.dev
HazAT
left a comment
There was a problem hiding this comment.
Good PR, before merging, let's discuss in which version we want to release this.
|
@HazAT @kamilogorek How does it differ from |
|
When will be this one be released? |
|
@diegopamio already shipped in |
@kamilogorek @HazAT Could you please clarify the difference between withScope and this additional argument? Thanks! |
|
@3zzy there's effectively none for most of the cases. The only difference is that |
|
@kamilogorek Thanks, but it doesn't seem to work when using a custom hub, for example: The error is tracked in Sentry but no tag or user ID is visible. |
|
@3zzy hub has a different function definition, that's why it doesn't work like that. Explicit scopes are meant to make "common usecases" easier to execute. Compare https://github.com/getsentry/sentry-javascript/blob/master/packages/minimal/src/index.ts#L24 to https://github.com/getsentry/sentry-javascript/blob/master/packages/hub/src/hub.ts#L157 If you want to use them in custom hubs, you need to tell the hub that what you pass to it is a var client1 = new Sentry.BrowserClient({ ... });
var hub1 = new Sentry.Hub(client1)
hub1.captureException(new Error("wat"), {
captureContext: {
user: {
id: 1337
},
tags: {
wat: "ok",
}
}
}); |
This PR introduces a second, optional argument to
captureExceptionandcaptureMessagemethods, that allows to provide some custom data directly to the scope.Provided data will be merged with what's already on the scope, unless explicitly cleared using a callback method.
It works in three variations:
Scopeinstance that'll extract the attributes fromList of allowed keys:
Example usages:
Ref: #1607
Notion: https://www.notion.so/sentry/Explicit-Scope-797e8b674010494d8854001281cf8769#8be8a9f0b4064842904d3e649bfac407
Asana: https://app.asana.com/0/1169125731075107/1175779896688409