Repository: elastic/apm-agent-python

Issue:
Cannot startup fastapi with apm 
With start apm in docker, I just set up agent in fastapi. Then I run app with uvicorn, it hangs.
**To Reproduce**

1. Start Service with docker compose [Reference](https://www.elastic.co/guide/en/apm/get-started/current/quick-start-overview.html)

![image](https://user-images.githubusercontent.com/5210569/124731645-fff5c880-df44-11eb-8b4f-876ec7b0ea3e.png)


- Test apm status
![image](https://user-images.githubusercontent.com/5210569/124731884-3af7fc00-df45-11eb-9f6b-856fc5ef8ae6.png)


2. Run the following simple FastAPI app:
```
from fastapi import FastAPI
from elasticapm.contrib.starlette import make_apm_client, ElasticAPM
import uvicorn


apm = make_apm_client({'SERVICE_NAME': 'test', 'SERVER_URL': 'http://0.0.0.0:8200'})
app = FastAPI()
app.add_middleware(ElasticAPM, client=apm)


@app.get("/")
def read_root():
    return {"Hello": "World"}


if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0', port=8000)
```

- Result
![image](https://user-images.githubusercontent.com/5210569/124732134-83171e80-df45-11eb-92ff-bbcc0c3598f4.png)



**Environment**
- OS: Mac
- Python version: `3.7.10`
- Framework and version: `fastapi==0.66.0`
- APM Server version: `image: docker.elastic.co/apm/apm-server:7.13.2`
- Agent version: `elastic-apm==6.3.0`



Cannot startup fastapi with apm 
With start apm in docker, I just set up agent in fastapi. Then I run app with uvicorn, it hangs.
**To Reproduce**

1. Start Service with docker compose [Reference](https://www.elastic.co/guide/en/apm/get-started/current/quick-start-overview.html)

![image](https://user-images.githubusercontent.com/5210569/124731645-fff5c880-df44-11eb-8b4f-876ec7b0ea3e.png)


- Test apm status
![image](https://user-images.githubusercontent.com/5210569/124731884-3af7fc00-df45-11eb-9f6b-856fc5ef8ae6.png)


2. Run the following simple FastAPI app:
```
from fastapi import FastAPI
from elasticapm.contrib.starlette import make_apm_client, ElasticAPM
import uvicorn


apm = make_apm_client({'SERVICE_NAME': 'test', 'SERVER_URL': 'http://0.0.0.0:8200'})
app = FastAPI()
app.add_middleware(ElasticAPM, client=apm)


@app.get("/")
def read_root():
    return {"Hello": "World"}


if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0', port=8000)
```

- Result
![image](https://user-images.githubusercontent.com/5210569/124732134-83171e80-df45-11eb-92ff-bbcc0c3598f4.png)



**Environment**
- OS: Mac
- Python version: `3.7.10`
- Framework and version: `fastapi==0.66.0`
- APM Server version: `image: docker.elastic.co/apm/apm-server:7.13.2`
- Agent version: `elastic-apm==6.3.0`





Discussion:

Resolving patch:
diff --git a/elasticapm/contrib/starlette/__init__.py b/elasticapm/contrib/starlette/__init__.py
--- a/elasticapm/contrib/starlette/__init__.py
+++ b/elasticapm/contrib/starlette/__init__.py
@@ -130,6 +130,9 @@ async def __call__(self, scope, receive, send):
             receive: receive awaitable callable
             send: send awaitable callable
         """
+        # we only handle the http scope, raise an exception for anything else
+        # see https://www.uvicorn.org/#the-asgi-interface
+        assert scope["type"] == "http"
 
         @functools.wraps(send)
         async def wrapped_send(message):


Test patch: