Beispiel #1
0
def add_flask_request_to_notification(notification):
    if not flask.request:
        return

    if notification.context is None:
        notification.context = "%s %s" % (flask.request.method,
                                          request_path(flask.request.environ))

    if "id" not in notification.user:
        notification.set_user(id=flask.request.remote_addr)
    notification.add_tab("session", dict(flask.session))
    if bugsnag.configure().send_environment:
        notification.add_tab("environment", dict(flask.request.environ))
    notification.add_tab(
        "request", {
            "url":
            flask.request.base_url,
            "headers":
            dict(flask.request.headers),
            "params":
            dict(flask.request.form),
            "data":
            flask.request.get_json(silent=True)
            or dict(body=flask.request.data)
        })
Beispiel #2
0
def add_pillar_request_to_notification(notification):
    """Adds request metadata to the Bugsnag notifications.

    This basically copies bugsnag.flask.add_flask_request_to_notification,
    but is altered to include Pillar-specific metadata.
    """
    from flask import request, session
    from bugsnag.wsgi import request_path
    import pillar.auth

    if not request:
        return

    notification.context = "%s %s" % (request.method,
                                      request_path(request.environ))

    if 'id' not in notification.user:
        user: pillar.auth.UserClass = pillar.auth.current_user._get_current_object(
        )
        notification.set_user(id=user.user_id,
                              email=user.email,
                              name=user.username)
        notification.user['roles'] = sorted(user.roles)
        notification.user['capabilities'] = sorted(user.capabilities)

    session_dict = dict(session)
    for key in SESSION_KEYS_TO_REMOVE:
        try:
            del session_dict[key]
        except KeyError:
            pass
    notification.add_tab("session", session_dict)
    notification.add_tab("environment", dict(request.environ))

    remote_addr = request.remote_addr
    forwarded_for = request.headers.get('X-Forwarded-For')
    if forwarded_for:
        remote_addr = f'{forwarded_for} (proxied via {remote_addr})'

    notification.add_tab(
        "request", {
            "method": request.method,
            "url": request.base_url,
            "headers": dict(request.headers),
            "params": dict(request.form),
            "data": {
                'request.data': request.data,
                'request.json': request.get_json()
            },
            "endpoint": request.endpoint,
            "remote_addr": remote_addr,
        })
def add_wsgi_request_data_to_notification(notification):
    if not hasattr(notification.request_config, "wsgi_environ"):
        return

    environ = notification.request_config.wsgi_environ
    request = Request(environ)

    notification.context = "%s %s" % (request.method, request_path(environ))
    notification.set_user(id=request.remote_addr)
    notification.add_tab("request", {
                "url": request.path_url,
                "headers": dict(request.headers),
                "params": dict(request.params),
            })
    notification.add_tab("environment", dict(request.environ))
Beispiel #4
0
def add_flask_request_to_notification(notification):
    if not request:
        return

    notification.context = "%s %s" % (request.method, request_path(request.environ))
    notification.set_user(id=request.remote_addr)
    notification.add_tab("session", dict(session))
    notification.add_tab("environment", dict(request.environ))
    notification.add_tab("request", {
        "url": request.base_url,
        "headers": dict(request.headers),
        "cookies": dict(request.cookies),
        "params": dict(request.form),
        "data": request.get_json() or dict(body=request.data)
    })
Beispiel #5
0
def add_wsgi_request_data_to_notification(notification):
    if not hasattr(notification.request_config, "wsgi_environ"):
        return

    environ = notification.request_config.wsgi_environ
    request = Request(environ)

    notification.context = "%s %s" % (request.method, request_path(environ))
    notification.set_user(id=request.remote_addr)
    notification.add_tab("request", {
        "url": request.path_url,
        "headers": dict(request.headers),
        "params": dict(request.params),
    })
    notification.add_tab("environment", dict(request.environ))
Beispiel #6
0
def handle_exception(exception, env):
    request = Request(env)

    bugsnag.configure_request(
        context="%s %s" % (request.method, request_path(env)),
        user_id=request.remote_addr,
        request_data={
            "url": request.base_url,
            "headers": dict(request.headers),
            "cookies": dict(request.cookies),
            "params": dict(request.form),
        },
        environment_data=dict(request.environ),
    )
    bugsnag.auto_notify(exception)
    bugsnag.clear_request_config()
Beispiel #7
0
def add_flask_request_to_notification(notification):
    if not request:
        return

    notification.context = "%s %s" % (request.method,
                                      request_path(request.environ))

    if 'id' not in notification.user:
        notification.set_user(id=request.remote_addr)
    notification.add_tab("session", dict(session))
    notification.add_tab("environment", dict(request.environ))
    notification.add_tab("request", {
        "url": request.base_url,
        "headers": dict(request.headers),
        "params": dict(request.form),
        "data": request.get_json() or dict(body=request.data)
    })
Beispiel #8
0
def __log_exception(sender, exception, **extra):
    bugsnag.configure_request(
        context="%s %s" % (request.method, request_path(request.environ)),
        user_id=request.remote_addr,
        request_data={
            "url": request.base_url,
            "headers": dict(request.headers),
            "cookies": dict(request.cookies),
            "params": dict(request.form),
        },
        session_data=dict(session),
        environment_data=dict(request.environ),
    )

    bugsnag.auto_notify(exception)

    bugsnag.clear_request_config()
Beispiel #9
0
def add_wsgi_request_data_to_notification(event):
    if not hasattr(event.request_config, "wsgi_environ"):
        return

    environ = event.request_config.wsgi_environ
    request = Request(environ)
    event.request = request
    path = request_path(environ)

    event.context = "%s %s" % (request.method, path)
    event.set_user(id=request.client_addr)
    event.add_tab(
        "request", {
            "url": "%s%s" % (request.application_url, path),
            "headers": dict(request.headers),
            "params": dict(request.params),
        })

    if bugsnag.configure().send_environment:
        event.add_tab("environment", dict(request.environ))