23
23
import aiohttp
24
24
import aiohttp .test_utils
25
25
import yarl
26
+ from http_server_mock import HttpServerMock
26
27
from pkg_resources import iter_entry_points
27
28
28
29
from opentelemetry import context
@@ -118,7 +119,7 @@ def test_status_codes(self):
118
119
self .assert_spans (
119
120
[
120
121
(
121
- "HTTP GET" ,
122
+ "GET" ,
122
123
(span_status , None ),
123
124
{
124
125
SpanAttributes .HTTP_METHOD : "GET" ,
@@ -212,7 +213,7 @@ def strip_query_params(url: yarl.URL) -> str:
212
213
self .assert_spans (
213
214
[
214
215
(
215
- "HTTP GET" ,
216
+ "GET" ,
216
217
(StatusCode .UNSET , None ),
217
218
{
218
219
SpanAttributes .HTTP_METHOD : "GET" ,
@@ -246,7 +247,7 @@ async def do_request(url):
246
247
self .assert_spans (
247
248
[
248
249
(
249
- "HTTP GET" ,
250
+ "GET" ,
250
251
(expected_status , None ),
251
252
{
252
253
SpanAttributes .HTTP_METHOD : "GET" ,
@@ -273,7 +274,7 @@ async def request_handler(request):
273
274
self .assert_spans (
274
275
[
275
276
(
276
- "HTTP GET" ,
277
+ "GET" ,
277
278
(StatusCode .ERROR , None ),
278
279
{
279
280
SpanAttributes .HTTP_METHOD : "GET" ,
@@ -300,7 +301,7 @@ async def request_handler(request):
300
301
self .assert_spans (
301
302
[
302
303
(
303
- "HTTP GET" ,
304
+ "GET" ,
304
305
(StatusCode .ERROR , None ),
305
306
{
306
307
SpanAttributes .HTTP_METHOD : "GET" ,
@@ -313,27 +314,37 @@ async def request_handler(request):
313
314
def test_credential_removal (self ):
314
315
trace_configs = [aiohttp_client .create_trace_config ()]
315
316
316
- url = "http://username:[email protected] /status/200"
317
- with self .subTest (url = url ):
317
+ app = HttpServerMock ("test_credential_removal" )
318
318
319
- async def do_request (url ):
320
- async with aiohttp .ClientSession (
321
- trace_configs = trace_configs ,
322
- ) as session :
323
- async with session .get (url ):
324
- pass
319
+ @app .route ("/status/200" )
320
+ def index ():
321
+ return "hello"
325
322
326
- loop = asyncio .get_event_loop ()
327
- loop .run_until_complete (do_request (url ))
323
+ url = "http://username:password@localhost:5000/status/200"
324
+
325
+ with app .run ("localhost" , 5000 ):
326
+ with self .subTest (url = url ):
327
+
328
+ async def do_request (url ):
329
+ async with aiohttp .ClientSession (
330
+ trace_configs = trace_configs ,
331
+ ) as session :
332
+ async with session .get (url ):
333
+ pass
334
+
335
+ loop = asyncio .get_event_loop ()
336
+ loop .run_until_complete (do_request (url ))
328
337
329
338
self .assert_spans (
330
339
[
331
340
(
332
- "HTTP GET" ,
341
+ "GET" ,
333
342
(StatusCode .UNSET , None ),
334
343
{
335
344
SpanAttributes .HTTP_METHOD : "GET" ,
336
- SpanAttributes .HTTP_URL : "http://httpbin.org/status/200" ,
345
+ SpanAttributes .HTTP_URL : (
346
+ "http://localhost:5000/status/200"
347
+ ),
337
348
SpanAttributes .HTTP_STATUS_CODE : int (HTTPStatus .OK ),
338
349
},
339
350
)
@@ -380,6 +391,7 @@ def test_instrument(self):
380
391
self .get_default_request (), self .URL , self .default_handler
381
392
)
382
393
span = self .assert_spans (1 )
394
+ self .assertEqual ("GET" , span .name )
383
395
self .assertEqual ("GET" , span .attributes [SpanAttributes .HTTP_METHOD ])
384
396
self .assertEqual (
385
397
f"http://{ host } :{ port } /test-path" ,
0 commit comments