elastic / elastic/apm-agent-python
Fix transaction tracing when running Django under ASGI
- Vorherrschende Sprache
- Python
- Sterne
- 431
- Forks
- 239
- Ø Merge
- 5 T. 10 Std.
- Gemergte PRs (30 T.)
- 7
Beschreibung
(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:
Beitragsleitfaden
Rechercherichtung
Beginne mit dem ASGI-Einstiegspunkt in asgi.py, insbesondere mit get_asgi_application und der Konfiguration von ProtocolTypeRouter, und reproduziere die Anfrage unter Daphne mit den gezeigten ELASTIC_APM-Einstellungen. Vergleiche das ASGI-Verhalten mit dem standardmäßigen WSGI/Django runserver und verfolge den standardmäßigen Django-Middleware-Pfad; abgeschlossen ist die Untersuchung, wenn eine normale HTTP-Anfrage als Request-Transaktion erscheint, nicht nur Celery-Tasks.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- django, python
- Bereich
- backend, observability-sre
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100