@@ -832,3 +832,42 @@ def test_basic_metric_both_semconv(self):
832832 dict (data_point .attributes ),
833833 )
834834 self .assertEqual (data_point .count , 1 )
835+
836+ def test_basic_metric_non_recording_span (self ):
837+ # tracer_provider = trace.NoOpTracerProvider()
838+ # trace.set_tracer_provider(tracer_provider=tracer_provider)
839+
840+ expected_attributes = {
841+ SpanAttributes .HTTP_STATUS_CODE : 200 ,
842+ SpanAttributes .HTTP_HOST : "examplehost" ,
843+ SpanAttributes .NET_PEER_PORT : 8000 ,
844+ SpanAttributes .NET_PEER_NAME : "examplehost" ,
845+ SpanAttributes .HTTP_METHOD : "GET" ,
846+ SpanAttributes .HTTP_FLAVOR : "1.1" ,
847+ SpanAttributes .HTTP_SCHEME : "http" ,
848+ }
849+
850+ with mock .patch ("opentelemetry.trace.INVALID_SPAN" ) as mock_span :
851+ RequestsInstrumentor ().uninstrument ()
852+ RequestsInstrumentor ().instrument (
853+ tracer_provider = trace .NoOpTracerProvider ()
854+ )
855+ mock_span .is_recording .return_value = False
856+ result = self .perform_request (self .URL )
857+ self .assertEqual (result .text , "Hello!" )
858+
859+ # self.assert_span(None, 0)
860+ self .assertFalse (mock_span .is_recording ())
861+ self .assertTrue (mock_span .is_recording .called )
862+ self .assertFalse (mock_span .set_attribute .called )
863+ self .assertFalse (mock_span .set_status .called )
864+ metrics_list = self .memory_metrics_reader .get_metrics_data ()
865+ # pylint: disable=too-many-nested-blocks
866+ for resource_metric in metrics_list .resource_metrics :
867+ for scope_metrics in resource_metric .scope_metrics :
868+ for metric in scope_metrics .metrics :
869+ for point in list (metric .data .data_points ):
870+ self .assertDictEqual (
871+ expected_attributes , dict (point .attributes )
872+ )
873+ self .assertEqual (point .count , 1 )
0 commit comments