33
33
from opentelemetry .semconv .trace import SpanAttributes
34
34
from opentelemetry .test .test_base import TestBase
35
35
from opentelemetry .test .wsgitestutil import WsgiTestBase
36
- from opentelemetry .trace import SpanKind
36
+ from opentelemetry .trace import SpanKind , StatusCode
37
37
from opentelemetry .util .http import (
38
38
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST ,
39
39
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE ,
@@ -494,7 +494,6 @@ def test_response_headers(self):
494
494
self .assertEqual (len (spans ), 3 )
495
495
self .assertTraceResponseHeaderMatchesSpan (response .headers , spans [1 ])
496
496
497
- self .memory_exporter .clear ()
498
497
set_global_response_propagator (orig )
499
498
500
499
def test_credential_removal (self ):
@@ -614,6 +613,7 @@ def test_http_client_success_response(self):
614
613
self .assertEqual (manual .name , "manual" )
615
614
self .assertEqual (server .name , "GET /" )
616
615
self .assertEqual (client .name , "GET" )
616
+ self .assertEqual (client .status .status_code , StatusCode .UNSET )
617
617
self .memory_exporter .clear ()
618
618
619
619
def test_http_client_failed_response (self ):
@@ -626,20 +626,22 @@ def test_http_client_failed_response(self):
626
626
server , client = self .sorted_spans (spans )
627
627
self .assertEqual (server .name , "GET /some-404" )
628
628
self .assertEqual (client .name , "GET" )
629
+ self .assertEqual (client .status .status_code , StatusCode .ERROR )
629
630
self .memory_exporter .clear ()
630
631
631
632
# when an exception is thrown
632
633
try :
633
634
response = self .fetch ("/some-404" , raise_error = True )
634
635
self .assertEqual (response .code , 404 )
635
636
except HTTPClientError :
636
- pass
637
+ pass # expected exception - continue
637
638
638
639
spans = self .memory_exporter .get_finished_spans ()
639
640
self .assertEqual (len (spans ), 2 )
640
641
server , client = self .sorted_spans (spans )
641
642
self .assertEqual (server .name , "GET /some-404" )
642
643
self .assertEqual (client .name , "GET" )
644
+ self .assertEqual (client .status .status_code , StatusCode .ERROR )
643
645
self .memory_exporter .clear ()
644
646
645
647
0 commit comments