@@ -188,7 +188,6 @@ async def test():
188188 assert ("Server-Timing" in response .headers )
189189 self .assertEqual (response .headers ["Server-Timing" ], "intid;desc=%s" % traceId )
190190
191-
192191 def test_client_get_500 (self ):
193192 async def test ():
194193 with async_tracer .start_active_span ('test' ):
@@ -345,6 +344,64 @@ async def test():
345344 assert ("Server-Timing" in response .headers )
346345 self .assertEqual (response .headers ["Server-Timing" ], "intid;desc=%s" % traceId )
347346
347+ def test_client_response_header_capture (self ):
348+ original_extra_headers = agent .extra_headers
349+ agent .extra_headers = ['X-Capture-This' ]
350+
351+ async def test ():
352+ with async_tracer .start_active_span ('test' ):
353+ async with aiohttp .ClientSession () as session :
354+ return await self .fetch (session , testenv ["wsgi_server" ] + "/response_headers" )
355+
356+ response = self .loop .run_until_complete (test ())
357+
358+ spans = self .recorder .queued_spans ()
359+ self .assertEqual (3 , len (spans ))
360+
361+ wsgi_span = spans [0 ]
362+ aiohttp_span = spans [1 ]
363+ test_span = spans [2 ]
364+
365+ self .assertIsNone (async_tracer .active_span )
366+
367+ # Same traceId
368+ traceId = test_span .t
369+ self .assertEqual (traceId , aiohttp_span .t )
370+ self .assertEqual (traceId , wsgi_span .t )
371+
372+ # Parent relationships
373+ self .assertEqual (aiohttp_span .p , test_span .s )
374+ self .assertEqual (wsgi_span .p , aiohttp_span .s )
375+
376+ # Error logging
377+ self .assertFalse (test_span .error )
378+ self .assertIsNone (test_span .ec )
379+ self .assertFalse (aiohttp_span .error )
380+ self .assertIsNone (aiohttp_span .ec )
381+ self .assertFalse (wsgi_span .error )
382+ self .assertIsNone (wsgi_span .ec )
383+
384+ self .assertEqual ("aiohttp-client" , aiohttp_span .n )
385+ self .assertEqual (200 , aiohttp_span .data .http .status )
386+ self .assertEqual (testenv ["wsgi_server" ] + "/response_headers" , aiohttp_span .data .http .url )
387+ self .assertEqual ("GET" , aiohttp_span .data .http .method )
388+ self .assertIsNotNone (aiohttp_span .stack )
389+ self .assertTrue (type (aiohttp_span .stack ) is list )
390+ self .assertTrue (len (aiohttp_span .stack ) > 1 )
391+ self .assertTrue ('http.X-Capture-This' in aiohttp_span .data .custom .tags )
392+
393+ assert ("X-Instana-T" in response .headers )
394+ self .assertEqual (response .headers ["X-Instana-T" ], traceId )
395+ assert ("X-Instana-S" in response .headers )
396+ self .assertEqual (response .headers ["X-Instana-S" ], wsgi_span .s )
397+ assert ("X-Instana-L" in response .headers )
398+ self .assertEqual (response .headers ["X-Instana-L" ], '1' )
399+ assert ("Server-Timing" in response .headers )
400+ self .assertEqual (response .headers ["Server-Timing" ], "intid;desc=%s" % traceId )
401+
402+ agent .extra_headers = original_extra_headers
403+
404+
348405 def test_client_error (self ):
349406 async def test ():
350407 with async_tracer .start_active_span ('test' ):
0 commit comments