def _nr_sanic_transaction_wrapper_(wrapped, instance, args, kwargs):
    request = _bind_request(*args, **kwargs)
    # If the request is a websocket request do not wrap it
    if request.headers.get('upgrade', '').lower() == 'websocket':
        return wrapped(*args, **kwargs)

    return web_transaction(request_method=request.method,
                           request_path=request.path,
                           query_string=request.query_string,
                           headers=request.headers)(wrapped)(*args, **kwargs)
Exemple #2
0
def _nr_request_wrapper(wrapped, instance, args, kwargs):
    request = _bind_handle(*args, **kwargs)

    # Ignore websockets
    if request.headers.get("upgrade", "").lower() == "websocket":
        return wrapped(*args, **kwargs)

    coro = wrapped(*args, **kwargs)

    if hasattr(coro, "__await__"):
        coro = coro.__await__()

    @asyncio.coroutine
    def _coro(*_args, **_kwargs):
        transaction = current_transaction()
        if transaction is None:
            response = yield from coro
            return response

        # Patch in should_ignore to all notice_error calls
        transaction._ignore_errors = should_ignore(transaction)

        import aiohttp

        transaction.add_framework_info(name="aiohttp",
                                       version=aiohttp.__version__)

        import aiohttp.web as _web

        try:
            response = yield from coro
        except _web.HTTPException as e:
            _nr_process_response(e, transaction)
            raise
        except Exception:
            nr_headers = transaction.process_response(500, ())
            request._nr_headers = dict(nr_headers)
            raise

        _nr_process_response(response, transaction)
        return response

    _coro = web_transaction(
        request_method=request.method,
        request_path=request.path,
        query_string=request.query_string,
        headers=request.raw_headers,
    )(_coro)

    return _coro(*args, **kwargs)