elastic / elastic/apm-agent-python

Fix transaction tracing when running Django under ASGI

Open
#1,953 4 comments 0 reactions 0 assignees View on GitHub
agent-python community triage
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:

Screenshot 2024-01-02 at 3 52 41 PM

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:

image

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.