elastic / elastic/apm-agent-python

No spans in APM when transaction is active

オープン
#1,070 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
agent-python
主要言語
Python
スター
431
フォーク
239
平均マージ
5日 10時間
マージ済み PR(30日)
7

説明

Hello! I have tried to use master branch to connect the dots in async background tasks (using the `elasticapm.get_client`)

Here is my "stack"
```

+-------------------+
| Backend Service |
| |
| with APM Agent |
+---------|---------+
| TraceParent is passed if request originated
| from another APM Agent, otherwise transaction is created
| and TraceParent is created and passed
+-------------------+
| uWSGI Spooler |
| Task Queue |
| (Async) |
+-------------------+
| Transaction is active, visible and connected in APM,
| however SPANs to this transactions are not visible anywhere
+---------|---------+
| Asynchronnous | -
| Background |
| Task |
+-------------------+

```

This somehow works, and I can see the whole transaction in APM even though the request only submits the tasks to queue and returns immidately after few miliseconds, so it is correctly paired with the trace id.

![Screenshot from 2021-03-15 10-35-11](https://user-images.githubusercontent.com/20358070/111132923-39f82480-857a-11eb-87e2-e11dd59899d3.png)

However inside the task, which has this transaction active, I am creating spans with `elasticapm.capture_span` decorator, and they are not visible in APM. I've added logging to really double check that there is indeed a valid active transaction.

simplified codeblock:
```python
logger.info(f"Transaction before caputuring span: {elasticapm.get_transaction_id()}")
with elasticapm.capture_span("my_span"):
do_stuff()
```

Which returns:
```
[info] Transaction before caputuring span: 44d90007a40c8780
```

That matches the transaction that I can see in APM:
![Screenshot from 2021-03-15 10-54-23](https://user-images.githubusercontent.com/20358070/111135380-e0ddc000-857c-11eb-835f-a154a1f23aa6.png)

But I do not see the spans in APM, what am I doing wrong?

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start with the reported Python entry points, elasticapm.get_client and elasticapm.capture_span, and reproduce the uWSGI Spooler path using the simplified example. Trace how the active transaction and captured span are handled in the asynchronous task; done means the span is visible in APM under the transaction shown in the report.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend, observability-sre
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
28/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。