Closed
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/react
SDK Version
7.1.1
Framework Version
7.1.1
Link to Sentry event
Steps to Reproduce
I have a small class that wraps sentry for capturing messages and exceptions. As shown below, for some reason, context does not get reliably sent.
public reportMessage(
message: string,
options?: { context?: Context; tags?: Tags }
) {
Sentry.withScope((scope) => {
if (options?.context) {
scope.setContext("context", this._stringifyContext(options.context))
}
if (options?.tags) {
scope.setTags(options.tags);
}
Sentry.captureMessage(message);
});
}
Below are two examples where it works every time. And I do not understand why.
If I do anything extra like this console log:
Sentry.withScope((scope) => {
if (options?.context) {
console.log("literally anything")
scope.setContext("context", this._stringifyContext(options.context));
}
if (options?.tags) {
scope.setTags(options.tags);
}
Sentry.captureMessage(message);
});
Or even just setting context to a new variable first like this:
Sentry.withScope((scope) => {
if (options?.context) {
const context = this._stringifyContext(options.context);
scope.setContext("context", context);
}
if (options?.tags) {
scope.setTags(options.tags);
}
Sentry.captureMessage(message);
});
Is this a bug with 7.0? This didn't happen before I upgraded.
Expected Result
Custom context should show up on issue in Sentry.io console
Actual Result
Custom context does not show up in Sentry.io console
Metadata
Metadata
Assignees
Labels
No labels