I ran into some issues running sanic in ASGI mode with New Relic. NR added support for Uvicorn recently, but using New Relic with sanic + uvicorn will give User Warning on every single request:
UserWarning: You have set a listener for "before_server_start" in ASGI mode. It will be executed as early as possible, but not before the ASGI server is started
This warning does show up on server start when not using NR. But it happens once, and so while annoying it’s tolerable.
When the app is started with
newrelic-admin, this warning shows up on every request to any endpoint. It is as if the app got restarted on every request (except that I don’t think that the app is restarting because none of my server start scripts get run and I don’t get the startup logs either). And while it does not break the app, it is extremely annoying to see this message on every request.
newrelic==126.96.36.199 sanic==20.6.3 Python 3.7.7 Python 3.8.2
I have tried a few variations of commands that give this behavior:
Version 1: NR gunicorn app with UvicornWorker - gives repeated warning
newrelic-admin \ run-program \ /path/to/bin/gunicorn \ app.app:app \ --bind 0.0.0.0:8000 \ --workers=4 \ --backlog 2048 \ --worker-class uvicorn.workers.UvicornWorker \ --timeout 30 \ --keep-alive 30 \ --worker-connections 1000 \ --max-requests 30000 \ --max-requests-jitter 5000
Version 2: NR uvicorn app - gives repeated warning
newrelic-admin \ run-program \ /path/to/bin/uvicorn \ app.app:app \ --host 0.0.0.0 \ --port 8000 \ --workers=4 \ --backlog 2048 \ --loop uvloop \ --no-access-log \ --proxy-headers
Version 3: NR sanic app - eventually I gave up and settled on just running sanic directly. This will not give any warning, but is also expected since uvicorn is not involved
newrelic-admin \ run-program \ /path/to/bin/python \ -m sanic \ app.app.app \ --host=0.0.0.0 \ --port=8000 \ --workers=4
Any help would be appreciated — if you think that this is only related to NR then I will try to resolve with them. You are just generally a lot more helpful than the support that they give me!
Also, if there is any way I could just disable this warning, that would be helpful also — because like I said, it doesn’t actually affect the app at all, it‘s just that seeing this warning every second pollutes the log tremendously.