aws / aws/aws-xray-sdk-python

Segment context not propagated when `asyncio.run_in_executor` is used

Aperta
#446 2 commenti 5 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
338
Fork
147
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

(Minimised) Example code:

```python
import asyncio

from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
from aws_xray_sdk.core.async_context import AsyncContext

import boto3

xray_recorder.configure(service="Test app", sampling=False, context=AsyncContext())
patch_all()

def run_task():
s3_client = boto3.client("s3")
s3_client.list_buckets()

async def main():
loop = asyncio.get_running_loop()
xray_recorder.begin_segment("test")
await loop.run_in_executor(None, run_task)
xray_recorder.end_segment()

asyncio.run(main())
```

Output:
```
cannot find the current segment/subsegment, please make sure you have a segment open
No segment found, cannot begin subsegment s3.
cannot find the current segment/subsegment, please make sure you have a segment open
cannot find the current segment/subsegment, please make sure you have a segment open
No segment to end
cannot find the current segment/subsegment, please make sure you have a segment open
```

I understand from the README that when using a thread pool (which is the default executor), the trace entity needs to be manually propagated. Could it be propagated automatically?

I'm asking because in the use case I have, a 3rd party library I'm using is making the call so I couldn't patch the call sites easily.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con le indicazioni della README sulla propagazione delle tracce nei pool di thread e sull’entry point AsyncContext utilizzato con loop.run_in_executor. Riproduci l’esempio ridotto, quindi traccia il modo in cui run_task ottiene il segmento corrente e verifica che l’esempio venga completato senza messaggi relativi a segmenti mancanti o sottosegmenti mancanti quando la propagazione è automatica.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, python
Ambito
backend, observability-sre
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.