@@ -790,6 +790,60 @@ def test_custom_meter_provider(self):
790
790
)
791
791
self .assertEqual (data_point .count , 1 )
792
792
793
+ def _run_disabled_tracing_metrics_attributes_test (
794
+ self ,
795
+ url : str ,
796
+ expected_attributes : dict ,
797
+ ) -> None :
798
+ with mock .patch ("opentelemetry.trace.INVALID_SPAN" ) as mock_span :
799
+ client = self .create_client (
800
+ self .create_transport (
801
+ tracer_provider = trace .NoOpTracerProvider ()
802
+ )
803
+ )
804
+ mock_span .is_recording .return_value = False
805
+ self .perform_request (url , client = client )
806
+
807
+ self .assertFalse (mock_span .is_recording ())
808
+ self .assertTrue (mock_span .is_recording .called )
809
+
810
+ metrics = self .assert_metrics (num_metrics = 1 )
811
+ duration_data_point = metrics [0 ].data .data_points [0 ]
812
+
813
+ self .assertEqual (duration_data_point .count , 1 )
814
+ self .assertEqual (
815
+ dict (duration_data_point .attributes ),
816
+ expected_attributes ,
817
+ )
818
+
819
+ def test_metrics_have_response_attributes_with_disabled_tracing (
820
+ self ,
821
+ ) -> None :
822
+ """Test that metrics have response attributes when tracing is disabled."""
823
+ self ._run_disabled_tracing_metrics_attributes_test (
824
+ url = self .URL ,
825
+ expected_attributes = {
826
+ SpanAttributes .HTTP_STATUS_CODE : 200 ,
827
+ SpanAttributes .HTTP_METHOD : "GET" ,
828
+ SpanAttributes .HTTP_SCHEME : "http" ,
829
+ },
830
+ )
831
+
832
+ def test_metrics_have_response_attributes_with_disabled_tracing_new_semconv (
833
+ self ,
834
+ ) -> None :
835
+ """Test that metrics have response attributes when tracing is disabled with new semantic conventions."""
836
+ self ._run_disabled_tracing_metrics_attributes_test (
837
+ url = "http://mock:8080/status/200" ,
838
+ expected_attributes = {
839
+ SERVER_ADDRESS : "mock" ,
840
+ HTTP_REQUEST_METHOD : "GET" ,
841
+ HTTP_RESPONSE_STATUS_CODE : 200 ,
842
+ NETWORK_PROTOCOL_VERSION : "1.1" ,
843
+ SERVER_PORT : 8080 ,
844
+ },
845
+ )
846
+
793
847
def test_response_hook (self ):
794
848
transport = self .create_transport (
795
849
tracer_provider = self .tracer_provider ,
0 commit comments