Skip to content

Make configureScope return a Promise #4407

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
ffxsam opened this issue Jan 12, 2022 · 4 comments
Closed

Make configureScope return a Promise #4407

ffxsam opened this issue Jan 12, 2022 · 4 comments

Comments

@ffxsam
Copy link

ffxsam commented Jan 12, 2022

Problem Statement

Working with configureScope is problematic in some environments (async). E.g:

async function one() {
  Sentry.configureScope(scope => {
    // ...
  });

  // other code that depends on the above
}

I've had to resort to writing a convenience function to handle things like adding to an existing context:

export function addToContext(
  contextName: string,
  data: Record<string, any>
): Promise<void> {
  return new Promise(resolve => {
    Sentry.configureScope(scope => {
      scope.setContext(contextName, {
        // @ts-ignore
        ...scope._contexts[contextName],
        ...data,
      });

      resolve();
    });
  });
}

It would be great if there were a built-in way to just use scope.* methods and have a Promise be returned. I think most people prefer them over callbacks.

Thanks!

Solution Brainstorm

No response

@getsentry-release
Copy link

Routing to @getsentry/team-webplatform for triage. ⏲️

@sl0thentr0py sl0thentr0py transferred this issue from getsentry/sentry Jan 14, 2022
@AbhiPrasad
Copy link
Member

Hey thanks for writing in. We're investigating this (slightly related: #2049), but backlogged for now as it's a breaking change.

@ffxsam
Copy link
Author

ffxsam commented Jan 18, 2022

Would there be a way to introduce the change in a non-breaking way? For example, configureScope could still accept a callback as an optional argument, and if the callback is missing, return a Promise.

@vladanpaunovic
Copy link
Contributor

Closing as a duplicate of #2049

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants