Segment context not propagated when `asyncio.run_in_executor` is used
- Vorherrschende Sprache
- Python
- Sterne
- 338
- Forks
- 147
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
(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.
Beitragsleitfaden
Rechercherichtung
Beginne mit den Hinweisen der README zur Weitergabe von Traces in Thread-Pools und dem AsyncContext-Einstiegspunkt, der mit loop.run_in_executor verwendet wird. Stelle das minimierte Beispiel nach und verfolge anschließend, wie run_task das aktuelle Segment abruft, und verifiziere, dass das Beispiel ohne Meldungen zu fehlenden Segmenten oder fehlenden Subsegmenten abgeschlossen wird, wenn die Weitergabe automatisch erfolgt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- aws, python
- Bereich
- backend, observability-sre
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100