in_segment_async doesn't get/pass the current Lambda segment
- Vorherrschende Sprache
- Python
- Sterne
- 338
- Forks
- 147
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Hello,
I am opening this issue on request of @NathanielRN after a discussion with him in https://github.com/aws/aws-xray-sdk-python/issues/310 .
The problem is that when we have API GW -> Lambda invocation and in the Lambda we use async , then we get 2 separate traces. One from API GW to Lambda and another from `in_segment_async` . To tie them together I have to use the following workaround:
```python
# get current segment
trace_id = xray_recorder.get_trace_entity().trace_id
parent_id = xray_recorder.current_segment().id
# enable xray to work with async
# even though Lambda has its own segment we need to create one async segment
xray_recorder.configure(context=AsyncContext())
async with xray_recorder.in_segment_async('add_brochure', traceid=trace_id, parent_id=parent_id) as segment:
...
```
But even then most of the times (usually works first time after deployment only) it doesn't work because I get the error:
```
[ERROR] AttributeError: 'NoneType' object has no attribute 'trace_id'
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 19, in lambda_handler
trace_id = xray_recorder.get_trace_entity().trace_id
```
Beitragsleitfaden
Rechercherichtung
Beginne damit, den hier beschriebenen API Gateway to Lambda-Ablauf zu reproduzieren, und untersuche dann xray_recorder.in_segment_async, get_trace_entity, current_segment und AsyncContext. Vergleiche das Verhalten mit der Diskussion in issue 310. Fertig ist die Aufgabe, wenn das asynchrone Segment ohne den Workaround mit dem Lambda-Trace verbunden bleibt und kein NoneType-Fehler für trace_id auftritt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- aws, python
- Bereich
- api, backend, observability
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100