Repository: elastic/apm-agent-python

Issue:
Elastic APM 6.13.0 agent errors when capturing long elasticsearch transactions
**Describe the bug**: 

**To Reproduce**

When capturing transactions to elasticsearch, Elastic APM throws errors when executing long transactions (e.g. async_scan), eventually causing the asynchronous event loop to cancel all tasks. 

```text
2022-10-31T09:05:05.200-04:00 | Traceback (most recent call last):
-- | --
  | 2022-10-31T09:05:05.200-04:00 | File "/usr/local/lib/python3.9/site-packages/elasticsearch/_async/helpers.py", line 490, in async_scan
  | 2022-10-31T09:05:05.200-04:00 | resp = await scroll_client.scroll(
  | 2022-10-31T09:05:05.200-04:00 | File "/usr/local/lib/python3.9/site-packages/elasticsearch/_async/client/__init__.py", line 3350, in scroll
  | 2022-10-31T09:05:05.200-04:00 | return await self.perform_request( # type: ignore[return-value]
  | 2022-10-31T09:05:05.200-04:00 | File "/usr/local/lib/python3.9/site-packages/elasticsearch/_async/client/_base.py", line 286, in perform_request
  | 2022-10-31T09:05:05.200-04:00 | meta, resp_body = await self.transport.perform_request(
  | 2022-10-31T09:05:05.200-04:00 | File "/usr/local/lib/python3.9/site-packages/elasticapm/instrumentation/packages/asyncio/elasticsearch.py", line 105, in call
  | 2022-10-31T09:05:05.200-04:00 | result_data = await wrapped(*args, **kwargs)
  | 2022-10-31T09:05:05.200-04:00 | File "/usr/local/lib/python3.9/site-packages/elastic_transport/_async_transport.py", line 272, in perform_request
  | 2022-10-31T09:05:05.200-04:00 | resp.meta.status,
  | 2022-10-31T09:05:05.200-04:00 | AttributeError: 'coroutine' object has no attribute 'meta'
```

Pinning elastic-apm~6.12.0 will solve the issue and it appears that it was introduced when Elasticsearch 8.0 support was added in [PR#1642](https://github.com/elastic/apm-agent-python/pull/1642/files) but I can't determine why because you guys did access the meta attribute safely with hasattr()? 

Please let me know if there is additional context I can add!

**Environment (please complete the following information)**
- OS: [e.g. Linux] debian:bullseye-slim (python:3.9-slim container image) x86
- Python version: 3.9
- Framework and version [e.g. Django 2.1]: N/A AWS Lambda Function
- APM Server version: 8.4.2
- Agent version: 6.13.0
- AWS Lambda Runtime: Custom container built w/ apm-lambda-extension.

```shell
$ pip3 freeze | grep elastic
elastic-apm==6.13.0
elastic-transport==8.4.0
elasticsearch==8.4.3
```

**Additional context**

Add any other context about the problem here.

- Agent config options <!-- be careful not to post sensitive information -->
  <details>
    <summary>Click to expand</summary>

    ```
    ELASTIC_APM_LOG_LEVEL: info
    ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS: 15
    ELASTIC_APM_DATA_FORWARDER_TIMEOUT_SECONDS: 3
    ```
  </details>
- `requirements.txt`: Poetry in use (`tool.poetry.dependencies` in replace)
  <details>
    <summary>Click to expand</summary>

    ```
    [tool.poetry.dependencies]
    python = "^3.9"
    elasticsearch = "^8"
    elastic-apm = "^6.13"
    pandas = "^1.4.3"
    python-dotenv = "^0.21.0"
    requests = "^2.28.1"
    python-dateutil = "^2.8.2"
    boto3 = "^1.25.4"
    psycopg2-binary = "^2.9.3"
    aiohttp = "^3.8.1"
    validators = "^0.20.0"
    ```
  </details>



Discussion:
Python Code
```python
async with AsyncElasticsearch(**elastic_context) as client:
    async for doc in async_scan(
          client=client,
          index='XXX',
          query=query,
          _source={
              "includes": ["XXX"],
              "excludes": ["XXX"]
          }
      ):
```
@brett-fitz Is the `AttributeError: 'coroutine' object has no attribute 'meta'` the only error you're seeing? You said:

> Elastic APM throws errors when executing long transactions 

Technically that's not an error in Elastic APM so I wanted to be sure there wasn't another error we were missing.
Apologize for the late response on this, I've finally been able to reproduce this again:
![image](https://user-images.githubusercontent.com/37186808/204680668-7d08e2c1-498e-4aaf-be1e-a6679839a20a.png)
Resp: <coroutine object AiohttpHttpNode.perform_request at 0x7f3de109a5c0>

Let me know if that helps!
https://github.com/elastic/apm-agent-python/blob/04f636dcbe88af8833a03e55c6e80a081cbfe9e9/elasticapm/instrumentation/packages/asyncio/elasticsearch.py#L59-L63

Seems bug appears during instrumentation of `AiohttpHttpNode.perform_request`. On 59 line the result of `wrapped` returned without `await`. 

Resolving patch:
diff --git a/elasticapm/instrumentation/packages/asyncio/elasticsearch.py b/elasticapm/instrumentation/packages/asyncio/elasticsearch.py
--- a/elasticapm/instrumentation/packages/asyncio/elasticsearch.py
+++ b/elasticapm/instrumentation/packages/asyncio/elasticsearch.py
@@ -56,7 +56,7 @@ def get_instrument_list(self):
     async def call(self, module, method, wrapped, instance, args, kwargs):
         span = execution_context.get_span()
         if not span or isinstance(span, DroppedSpan):
-            return wrapped(*args, **kwargs)
+            return await wrapped(*args, **kwargs)
 
         self._update_context_by_request_data(span.context, instance, args, kwargs)
 


Test patch: