newrelic-python-agent icon indicating copy to clipboard operation
newrelic-python-agent copied to clipboard

New Relic ASGI wrapper stop working

Open jefer94 opened this issue 1 year ago • 7 comments

Versions

pipenv=2023.12.1
django=5.0.5
python=3.12.3

Worker

uvicorn.workers.UvicornWorker

Cloud

Heroku

Env

WEB_WORKER_CONNECTION=160
WEB_WORKER_CLASS=uvicorn.workers.UvicornWorker
CELERY_POOL=prefork
WEB_WORKERS=2
WEB_MAX_REQUESTS=100
WEB_MAX_REQUESTS_JITTER=50
WEB_PRELOAD=0
NOWRAP_APP=0

Script

#!/bin/env bash

WEB_WORKER_CONNECTION=${WEB_WORKER_CONNECTION:-200}
WEB_WORKER_CLASS=${WEB_WORKER_CLASS:-uvicorn.workers.UvicornWorker}
CELERY_POOL=${CELERY_POOL:-prefork}
WEB_WORKERS=${WEB_WORKERS:-2}
WEB_TIMEOUT=${WEB_TIMEOUT:-29}
WEB_MAX_REQUESTS=${WEB_MAX_REQUESTS:-6000}
WEB_MAX_REQUESTS_JITTER=${WEB_MAX_REQUESTS_JITTER:-3000}
WEB_PRELOAD=${WEB_PRELOAD:-1}
SSR=${SSR:-0}

export NEW_RELIC_METADATA_COMMIT=$HEROKU_SLUG_COMMIT;
export CORALOGIX_SUBSYSTEM=web;
export CELERY_POOL=$CELERY_POOL;

if [ "$WEB_PRELOAD" = "1" ]; then
    GUNICORN_PARAMS="--preload"
else
    GUNICORN_PARAMS=""
fi

if [ "$WEB_WORKER_CLASS" = "uvicorn.workers.UvicornWorker" ]; then
    export SERVER_TYPE=asgi;
else
    export SERVER_TYPE=wsgi;
fi

newrelic-admin run-program bin/start-pgbouncer-stunnel \
    gunicorn breathecode.$SERVER_TYPE --timeout $WEB_TIMEOUT --workers $WEB_WORKERS \
        --worker-connections $WEB_WORKER_CONNECTION --worker-class $WEB_WORKER_CLASS \
        --max-requests $WEB_MAX_REQUESTS --max-requests-jitter $WEB_MAX_REQUESTS_JITTER \
        $GUNICORN_PARAMS &

pid1=$!

if [ "$SSR" = "1" ]; then
    curl -fsSL https://bun.sh/install | bash
    export BUN_INSTALL="$HOME/.bun"
    export PATH=$BUN_INSTALL/bin:$PATH

    newrelic-admin run-program bun ssr.ts &
    pid2=$!
    wait $pid2
fi

wait $pid1

asgi.py

"""
WSGI config for breathecode project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""

# keeps this above
import newrelic.agent

newrelic.agent.initialize()

# the rest of your ASGI file contents go here
import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'breathecode.settings')

application = get_asgi_application()
if os.getenv('NOWRAP_APP') != '1':
    application = newrelic.agent.ASGIApplicationWrapper(application)

Log

2024-05-28T20:06:58.493920+00:00 heroku[router]: at=info method=GET path="/" host=breathecode-test.herokuapp.com request_id=bbcdf32f-d6b6-4df7-baed-f80afc42fd4e fwd="190.240.161.182" dyno=web.1 connect=0ms service=4ms status=500 bytes=212 protocol=https
2024-05-28T20:06:58.492684+00:00 app[web.1]: [2024-05-28 20:06:58 +0000] [29] [ERROR] Exception in ASGI application
2024-05-28T20:06:58.492750+00:00 app[web.1]: Traceback (most recent call last):
2024-05-28T20:06:58.492766+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 407, in run_asgi
2024-05-28T20:06:58.492767+00:00 app[web.1]:     result = await app(  # type: ignore[func-returns-value]
2024-05-28T20:06:58.492767+00:00 app[web.1]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.492768+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
2024-05-28T20:06:58.492768+00:00 app[web.1]:     return await self.app(scope, receive, send)
2024-05-28T20:06:58.492768+00:00 app[web.1]:                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.492768+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/newrelic/api/asgi_application.py", line 258, in nr_asgi_wrapper
2024-05-28T20:06:58.492769+00:00 app[web.1]:     return wrapped(*args, **kwargs)
2024-05-28T20:06:58.492769+00:00 app[web.1]:            ^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.492771+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/newrelic/api/wsgi_application.py", line 669, in _nr_wsgi_application_wrapper_
2024-05-28T20:06:58.492771+00:00 app[web.1]:     result = wrapped(environ, _start_response)
2024-05-28T20:06:58.492771+00:00 app[web.1]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.492772+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/newrelic/api/asgi_application.py", line 363, in nr_asgi_wrapper
2024-05-28T20:06:58.492772+00:00 app[web.1]:     return nr_async_asgi(*_bind_receive_send(*args, **kwargs))
2024-05-28T20:06:58.492773+00:00 app[web.1]:                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.492773+00:00 app[web.1]: TypeError: _bind_receive_send() missing 1 required positional argument: 'send'
2024-05-28T20:06:58.493146+00:00 app[web.1]: 190.240.161.182:0 - "GET / HTTP/1.1" 500
2024-05-28T20:06:58.837909+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=breathecode-test.herokuapp.com request_id=d7d55ec6-d5b9-4955-85b9-70734617f2d2 fwd="190.240.161.182" dyno=web.1 connect=1ms service=15ms status=500 bytes=212 protocol=https
2024-05-28T20:06:58.836773+00:00 app[web.1]: [2024-05-28 20:06:58 +0000] [28] [ERROR] Exception in ASGI application
2024-05-28T20:06:58.836839+00:00 app[web.1]: Traceback (most recent call last):
2024-05-28T20:06:58.836857+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 407, in run_asgi
2024-05-28T20:06:58.836858+00:00 app[web.1]:     result = await app(  # type: ignore[func-returns-value]
2024-05-28T20:06:58.836858+00:00 app[web.1]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.836858+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
2024-05-28T20:06:58.836858+00:00 app[web.1]:     return await self.app(scope, receive, send)
2024-05-28T20:06:58.836859+00:00 app[web.1]:                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.836859+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/newrelic/api/asgi_application.py", line 258, in nr_asgi_wrapper
2024-05-28T20:06:58.836859+00:00 app[web.1]:     return wrapped(*args, **kwargs)
2024-05-28T20:06:58.836859+00:00 app[web.1]:            ^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.836861+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/newrelic/api/wsgi_application.py", line 669, in _nr_wsgi_application_wrapper_
2024-05-28T20:06:58.836861+00:00 app[web.1]:     result = wrapped(environ, _start_response)
2024-05-28T20:06:58.836861+00:00 app[web.1]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.836861+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.12/site-packages/newrelic/api/asgi_application.py", line 363, in nr_asgi_wrapper
2024-05-28T20:06:58.836861+00:00 app[web.1]:     return nr_async_asgi(*_bind_receive_send(*args, **kwargs))
2024-05-28T20:06:58.836861+00:00 app[web.1]:                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-28T20:06:58.836862+00:00 app[web.1]: TypeError: _bind_receive_send() missing 1 required positional argument: 'send'
2024-05-28T20:06:58.836931+00:00 app[web.1]: 190.240.161.182:0 - "GET /favicon.ico HTTP/1.1" 500

jefer94 avatar May 28 '24 20:05 jefer94