aws / aws/aws-xray-sdk-python

global_sdk_config.is_enabled() is ignored for async

Abierto
#170 3 comentarios 2 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Python
Estrellas
339
Forks
147
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

When disabling the XRay API using global_sdk_config. I'm still getting errors when using the Async pattern.

I've created the following script to demonstrate the bug:

```
import asyncio
import sys

from aws_xray_sdk import global_sdk_config
from aws_xray_sdk.core import xray_recorder

# Enable SDK based on argument
if 'enable' in sys.argv:
print('Enabling XRay')
global_sdk_config.set_sdk_enabled(True)
else:
print('Disbling XRay')
global_sdk_config.set_sdk_enabled(False)

@xray_recorder.capture('normal')
def test_normal():
print('IN NORMAL')

@xray_recorder.capture_async('async')
async def test_async():
print('IN ASYNC')

if 'normal' in sys.argv:
print('EXECUTE NORMAL')
test_normal()

if 'async' in sys.argv:
print('EXECUTE ASYNC')
asyncio.get_event_loop().run_until_complete(test_async())
```

### [PASS] Enable XRay, execute sync call
If I call this script:
```
python test.py enable normal
```
The output is:
```
Enabling XRay
EXECUTE NORMAL
cannot find the current segment/subsegment, please make sure you have a segment open
Traceback (most recent call last):
File "test.py", line 27, in
test_normal()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/models/subsegment.py", line 58, in __call__
meta_processor=None,
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 417, in record_subsegment
subsegment = self.begin_subsegment(name, namespace)
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 284, in begin_subsegment
segment = self.current_segment()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 267, in current_segment
entity = self.get_trace_entity()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 369, in get_trace_entity
return self.context.get_trace_entity()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/context.py", line 93, in get_trace_entity
return self.handle_context_missing()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/context.py", line 118, in handle_context_missing
raise SegmentNotFoundException(MISSING_SEGMENT_MSG)
aws_xray_sdk.core.exceptions.exceptions.SegmentNotFoundException: cannot find the current segment/subsegment, please make sure you have a segment open
```
Which is what I would expect. I never created a segment, so it is perfectly correct to raise exception.

### [PASS] Disable XRay, execute sync call
When I call the script again:
```
python test.py disable normal
```
The output is:
```
Disbling XRay
EXECUTE NORMAL
cannot find the current segment/subsegment, please make sure you have a segment open
IN NORMAL
```

Again correct. (I'm not entirely sure if the "cannot find the current segment/subsegment, please make sure you have a segment open" message is justified, as I've disabled the SDK, I actually am not expecting it to report me anything. But I'll let that one slide for this report.

### [PASS] Enable XRay, execute async call
I execute the script:
```
python test.py enable async
```
And output:
```
Enabling XRay
EXECUTE ASYNC
cannot find the current segment/subsegment, please make sure you have a segment open
Traceback (most recent call last):
File "test.py", line 31, in
asyncio.get_event_loop().run_until_complete(test_async())
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/async_recorder.py", line 33, in __call__
meta_processor=None,
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/async_recorder.py", line 75, in record_subsegment_async
subsegment = self.begin_subsegment(name, namespace)
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 284, in begin_subsegment
segment = self.current_segment()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 267, in current_segment
entity = self.get_trace_entity()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 369, in get_trace_entity
return self.context.get_trace_entity()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/context.py", line 93, in get_trace_entity
return self.handle_context_missing()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/context.py", line 118, in handle_context_missing
raise SegmentNotFoundException(MISSING_SEGMENT_MSG)
aws_xray_sdk.core.exceptions.exceptions.SegmentNotFoundException: cannot find the current segment/subsegment, please make sure you have a segment open
```

Just like the synchronous call. I was expecting this.

### [FAIL] Disable XRay, execute async call
I execute the script again:
```
python test.py disable async
```

And now the fun begins:
```
Disbling XRay
EXECUTE ASYNC
cannot find the current segment/subsegment, please make sure you have a segment open
Traceback (most recent call last):
File "test.py", line 31, in
asyncio.get_event_loop().run_until_complete(test_async())
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/async_recorder.py", line 33, in __call__
meta_processor=None,
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/async_recorder.py", line 75, in record_subsegment_async
subsegment = self.begin_subsegment(name, namespace)
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 284, in begin_subsegment
segment = self.current_segment()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 267, in current_segment
entity = self.get_trace_entity()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 369, in get_trace_entity
return self.context.get_trace_entity()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/context.py", line 93, in get_trace_entity
return self.handle_context_missing()
File "/home/idoorn/anaconda2/envs/bazelenv36/lib/python3.6/site-packages/aws_xray_sdk/core/context.py", line 118, in handle_context_missing
raise SegmentNotFoundException(MISSING_SEGMENT_MSG)
aws_xray_sdk.core.exceptions.exceptions.SegmentNotFoundException: cannot find the current segment/subsegment, please make sure you have a segment open
````

And it fails.. The XRay SDK is disabled, but still it complains that I have to open the segment.
I guess somewhere there is a check missing for the global_sdk_config.is_enabled() state.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Reproduce los cuatro casos del script del issue y, después, inspecciona aws_xray_sdk/core/async_recorder.py y los puntos de entrada del recorder que se muestran en el traceback. Compara la ruta deshabilitada con el decorador síncrono y verifica que las llamadas asíncronas deshabilitadas se completen sin buscar un segmento, mientras que las llamadas habilitadas mantienen el comportamiento existente.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
observability-sre
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.