@@ -798,6 +798,7 @@ def _run_disabled_tracing_metrics_attributes_test(
798798 self ,
799799 url : str ,
800800 expected_attributes : dict ,
801+ expected_number_of_metrics : int = 1 ,
801802 ) -> None :
802803 with mock .patch ("opentelemetry.trace.INVALID_SPAN" ) as mock_span :
803804 client = self .create_client (
@@ -811,7 +812,9 @@ def _run_disabled_tracing_metrics_attributes_test(
811812 self .assertFalse (mock_span .is_recording ())
812813 self .assertTrue (mock_span .is_recording .called )
813814
814- metrics = self .assert_metrics (num_metrics = 1 )
815+ metrics = self .assert_metrics (
816+ num_metrics = expected_number_of_metrics
817+ )
815818 duration_data_point = metrics [0 ].data .data_points [0 ]
816819
817820 self .assertEqual (duration_data_point .count , 1 )
@@ -823,14 +826,35 @@ def _run_disabled_tracing_metrics_attributes_test(
823826 def test_metrics_have_response_attributes_with_disabled_tracing (
824827 self ,
825828 ) -> None :
826- """Test that metrics have response attributes when tracing is disabled."""
829+ """Test that metrics have response attributes when tracing is disabled for old
830+ semantic conventions."""
827831 self ._run_disabled_tracing_metrics_attributes_test (
828- url = self . URL ,
832+ url = "http://mock:8080/status/200" ,
829833 expected_attributes = {
830834 HTTP_STATUS_CODE : 200 ,
831835 HTTP_METHOD : "GET" ,
832836 HTTP_SCHEME : "http" ,
833837 },
838+ expected_number_of_metrics = 1 ,
839+ )
840+
841+ def test_metrics_have_response_attributes_with_disabled_tracing_both_semconv (
842+ self ,
843+ ) -> None :
844+ """Test that metrics have response attributes when tracing is disabled for both
845+ semantic conventions."""
846+ self ._run_disabled_tracing_metrics_attributes_test (
847+ url = "http://mock:8080/status/200" ,
848+ expected_attributes = {
849+ HTTP_STATUS_CODE : 200 ,
850+ HTTP_METHOD : "GET" ,
851+ HTTP_SCHEME : "http" ,
852+ HTTP_FLAVOR : "1.1" ,
853+ HTTP_HOST : "mock" ,
854+ NET_PEER_NAME : "mock" ,
855+ NET_PEER_PORT : 8080 ,
856+ },
857+ expected_number_of_metrics = 2 ,
834858 )
835859
836860 def test_metrics_have_response_attributes_with_disabled_tracing_new_semconv (
@@ -846,6 +870,7 @@ def test_metrics_have_response_attributes_with_disabled_tracing_new_semconv(
846870 NETWORK_PROTOCOL_VERSION : "1.1" ,
847871 SERVER_PORT : 8080 ,
848872 },
873+ expected_number_of_metrics = 1 ,
849874 )
850875
851876 def test_response_hook (self ):
0 commit comments