elastic / elastic/apm-agent-python
Fix transaction tracing when running Django under ASGI
- Dominant language
- Python
- Stars
- 431
- Forks
- 239
- Avg merge
- 5d 10h
- Merged PRs (30d)
- 7
Description
(Moved from [original discussion](https://github.com/elastic/apm-agent-python/issues/1548#issuecomment-1875952921))
When running Django under ASGI, the middleware that Elastic APM injects is not tracking standard Django request transactions.
Here's my `asgi.py`:
```python
django_asgi_app = get_asgi_application()
application = ProtocolTypeRouter(
{
"http": django_asgi_app,
}
)
```
My `settings.ELASTIC_APM`:
```python
{'SERVICE_NAME': 'myapp',
'SERVER_URL': 'http://fleet-server:8200',
'SECRET_TOKEN': '*************',
'ENVIRONMENT': 'development',
'DEBUG': True}
```
I've browsed several pages and waited for Fleet to flush but all I see are Celery tasks:
Nothing is logged as a `request` transaction type by the standard Django middleware when running under Daphne.
If I switch the project back to standard WSGI/Django runserver, it logs request transactions:
Contributor guide
Assessment
This issue has not been assessed yet.