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.

Cannot push user scope using 0.13.2 and Flask

See original GitHub issue

Here’s my decorator that I use to set the scope when necessary

def sentry_configure_scope(func):
    """
    This decorator will set the user scope for sentry
    """

    @wraps(func)
    def decorated_function(*args, **kwargs):
        if session['token']:
            with configure_scope() as scope:
                token = session['token']
                claims = decode(token, verify=False)
                u = {
                    "id": claims['identity']['client_id'],
                    "username": "" + claims['identity']['first_name'] + " " + claims['identity']['last_name'],
                    "email": claims['identity']['email']
                }
                scope.set_user(u)
        return func(*args, **kwargs)

    return decorated_function

I’ve checked using the pycharm debugger and it seems that the scope._user is correctly set with the dict but once on sentry.io, the user scope is nowhere to be found… Any guess ? (only tested on local, maybe that’s it ?)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
untitakercommented, Nov 20, 2019

Glad to hear that!

1reaction
untitakercommented, Nov 20, 2019

@Seluj78 try

def configure_user_scope(event, hint):
    if session["token"]:
        with sentry_sdk.configure_scope() as scope:
            token = session["token"]
            claims = decode(token, verify=False)
            u = {
                "id": claims["identity"]["client_id"],
                "username": ""
                + claims["identity"]["first_name"]
                + " "
                + claims["identity"]["last_name"],
                "email": claims["identity"]["email"],
            }
            event.setdefault("user", {}).update(u)
    return event

scopes are not a thing inside before_send

Read more comments on GitHub >

github_iconTop Results From Across the Web

working outside of application context - Flask - Stack Overflow
This typically means that you attempted to use functionality that needed the current application. To solve this, set up an application context with...
Read more >
Flask-Security Documentation
Flask -Security allows you to quickly add common security mechanisms to your Flask application. They include: 1. Session based authentication.
Read more >
Deploying Python Flask microservices to AWS using open ...
We will use ECR as our registry. Let's build and push our container image to ECR. 1. First, you will need to create...
Read more >
The Application Context — Flask Documentation (2.2.x)
When using the app factory pattern or writing reusable blueprints or extensions there won't be an app instance to import at all. Flask...
Read more >
flask-restplus is broken by Werkzeug 1.0.0 · Issue #777 - GitHub
Temporary workaround: use Werkzeug==0.16.1. This solution worked for me as well. for me flask-restplus installed Werkzeug [required: >=0.15, ...
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