question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Context not being reliably set in withScope. Potential v7 regression.

See original GitHub issue

Is there an existing issue for this?

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

https://sentry.io/organizations/ternary/issues/3191835938/?environment=test&project=5634786&query=is%3Aunresolved

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
AbhiPrasadcommented, Jun 17, 2022
1reaction
AbhiPrasadcommented, Jun 17, 2022

Good catch! We’ll be fixing this ASAP and cutting a release very soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sentry-javascript/CHANGELOG.md at master
JS SDK works in older browsers that do not support ES6 or ES6+ (e.g. object spread) features. feat(react): Use state context for Redux...
Read more >
Multicollinearity in Regression Analysis: Problems, ...
Multicollinearity is when independent variables in a regression model are correlated. I explore its problems, testing your model for it, and solutions.
Read more >
Contexts and Dependency Injection for the Java EE platform
Getting Start with Weld, the CDI Reference Implementation . ... Prior to Java EE 6, there was no clear definition of the term...
Read more >
Scopes and Hubs for JavaScript
When an event is captured and sent to Sentry, SDKs will merge that event data with extra information from the current scope.
Read more >
Fix list for IBM WebSphere Application Server V8.5
IBM WebSphere Application Server provides periodic fixes for the base and Network Deployment editions of release V8.5. The following is a complete listing ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found