Closed jefer94 closed 1 month ago
What version of the agent are you using?
I'm not really sure how, but it looks like you have some double instrumentation going on here. In particular these lines of the stack trace look rather problematic:
packages/newrelic/api/asgi_application.py", line 258, in nr_asgi_wrapper
packages/newrelic/api/wsgi_application.py", line 669, in _nr_wsgi_application_wrapper_
For some reason it is wrapping wsgi in asgi. I notice you are manually applying our instrumentation which you should not need to do. Can you try removing the manual instrumentation and just let it automatically instrument instead?
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'breathecode.settings')
application = get_asgi_application()
I'm using 9.10.0
I don't get you, I'm setting DJANGO_SETTINGS_MODULE
and NewRelic can't know that value, right? with instrumentation
what should I remove?
https://github.com/breatheco-de/apiv2/blob/development/Pipfile.lock
I'm not really sure how, but it looks like you have some double instrumentation going on here. In particular these lines of the stack trace look rather problematic:
packages/newrelic/api/asgi_application.py", line 258, in nr_asgi_wrapper packages/newrelic/api/wsgi_application.py", line 669, in _nr_wsgi_application_wrapper_
For some reason it is wrapping wsgi in asgi. I notice you are manually applying our instrumentation which you should not need to do. Can you try removing the manual instrumentation and just let it automatically instrument instead?
import os from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'breathecode.settings') application = get_asgi_application()
Mmm I tried
application = newrelic.agent.ASGIApplicationWrapper()
And this didn't work
File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/home/jefer/dev/work/apiv2/breathecode/asgi.py", line 25, in <module>
application = newrelic.agent.ASGIApplicationWrapper()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ASGIApplicationWrapper() missing 1 required positional argument: 'wrapped'
I don't know what you mean with instrumentation
I'm suggesting that you use the newrelic-admin
as your entry point instead of calling the newrelic api directly. For example: newrelic-admin gunicorn --bind :8000 --workers 3 breathecode.wsgi:application
and similarly newrelic-admin uvicorn --bind :8000 --workers 3 breathecode.asgi:application
. Then in your code you can remove the calls to newrelic.agent.initialize()
and application = newrelic.agent.ASGIApplicationWrapper(application)
. Also, as an aside, if you want to disable the instrumentation you can use the following environment variable (instead of an if statement like you have above): NEW_RELIC_MONITOR_MODE=false
.
When running with newrelic-admin
it will automatically apply the instrumentation correctly based on whether you are using ASGI or WSGI. Based on what you posted above it looks like you are manually wrapping your application object in a newrelic api wrapper called, ASGIApplicationWrapper
. This is unnecessary and could be causing it to wrap our asgi application wrapper around our wsgi application wrapper which is what that stack trace is indicating. The stack trace makes me think you are applying our newrelic api incorrectly and it is causing a crash. This can be understandably tricky to do, which is why we provide the newrelic-admin
script as it just takes care of all that stuff for you. Our instrumentation automatically detects various web application frameworks (including Django) and automatically applies the appropriate wsgi and asgi application wrappers so there's no need to call our api directly and apply instrumentation yourself.
It fixed my issue, but this behavior is really weird
Work has been completed on this issue.
Versions
Worker
uvicorn.workers.UvicornWorker
Cloud
Heroku
Env
Script
asgi.py
Log