1
+ import logging
2
+
1
3
import pytest
2
4
from aiohttp import ClientSession
3
5
4
6
from aws_xray_sdk .core import xray_recorder
5
7
from aws_xray_sdk .core .async_context import AsyncContext
8
+ from aws_xray_sdk .core .context import MISSING_SEGMENT_MSG
6
9
from aws_xray_sdk .core .exceptions .exceptions import SegmentNotFoundException
7
10
from aws_xray_sdk .ext .util import strip_url , get_hostname
8
11
from aws_xray_sdk .ext .aiohttp .client import aws_xray_trace_config
@@ -144,7 +147,8 @@ async def test_no_segment_raise(loop, recorder):
144
147
pass
145
148
146
149
147
- async def test_no_segment_not_raise (loop , recorder ):
150
+ async def test_no_segment_log_error (loop , recorder , caplog ):
151
+ caplog .set_level (logging .ERROR )
148
152
xray_recorder .configure (context_missing = 'LOG_ERROR' )
149
153
trace_config = aws_xray_trace_config ()
150
154
status_code = 200
@@ -155,3 +159,19 @@ async def test_no_segment_not_raise(loop, recorder):
155
159
156
160
# Just check that the request was done correctly
157
161
assert status_received == status_code
162
+ assert MISSING_SEGMENT_MSG in [rec .message for rec in caplog .records ]
163
+
164
+
165
+ async def test_no_segment_ignore_error (loop , recorder , caplog ):
166
+ caplog .set_level (logging .ERROR )
167
+ xray_recorder .configure (context_missing = 'IGNORE_ERROR' )
168
+ trace_config = aws_xray_trace_config ()
169
+ status_code = 200
170
+ url = 'http://{}/status/{}?foo=bar' .format (BASE_URL , status_code )
171
+ async with ClientSession (loop = loop , trace_configs = [trace_config ]) as session :
172
+ async with session .get (url ) as resp :
173
+ status_received = resp .status
174
+
175
+ # Just check that the request was done correctly
176
+ assert status_received == status_code
177
+ assert MISSING_SEGMENT_MSG not in [rec .message for rec in caplog .records ]
0 commit comments