@@ -565,7 +565,9 @@ def test_basic_metric_success_new_semconv(self):
565
565
)
566
566
self .assertEqual (point .count , 1 )
567
567
if metric .name == "http.server.request.duration" :
568
- self .assertAlmostEqual (duration_s * 0.1 , point .sum , places = 1 )
568
+ self .assertAlmostEqual (
569
+ duration_s * 0.1 , point .sum , places = 1
570
+ )
569
571
elif metric .name == "http.server.response.body.size" :
570
572
self .assertEqual (25 , point .sum )
571
573
elif metric .name == "http.server.request.body.size" :
@@ -617,7 +619,9 @@ def test_basic_metric_success_both_semconv(self):
617
619
self .assertEqual (point .count , 1 )
618
620
self .assertAlmostEqual (duration , point .sum , delta = 350 )
619
621
if metric .name == "http.server.request.duration" :
620
- self .assertAlmostEqual (duration_s * 0.1 , point .sum , places = 1 )
622
+ self .assertAlmostEqual (
623
+ duration_s * 0.1 , point .sum , places = 1
624
+ )
621
625
self .assertDictEqual (
622
626
expected_duration_attributes_new ,
623
627
dict (point .attributes ),
@@ -726,7 +730,9 @@ def test_basic_metric_nonstandard_http_method_success_new_semconv(self):
726
730
)
727
731
self .assertEqual (point .count , 1 )
728
732
if metric .name == "http.server.request.duration" :
729
- self .assertAlmostEqual (duration_s * 0.1 , point .sum , places = 1 )
733
+ self .assertAlmostEqual (
734
+ duration_s * 0.1 , point .sum , places = 1
735
+ )
730
736
elif metric .name == "http.server.response.body.size" :
731
737
self .assertEqual (31 , point .sum )
732
738
elif metric .name == "http.server.request.body.size" :
@@ -777,7 +783,9 @@ def test_basic_metric_nonstandard_http_method_success_both_semconv(self):
777
783
if isinstance (point , HistogramDataPoint ):
778
784
self .assertEqual (point .count , 1 )
779
785
if metric .name == "http.server.request.duration" :
780
- self .assertAlmostEqual (duration_s * 0.1 , point .sum , places = 1 )
786
+ self .assertAlmostEqual (
787
+ duration_s * 0.1 , point .sum , places = 1
788
+ )
781
789
self .assertDictEqual (
782
790
expected_duration_attributes_new ,
783
791
dict (point .attributes ),
@@ -861,7 +869,9 @@ def test_basic_post_request_metric_success_new_semconv(self):
861
869
if isinstance (point , HistogramDataPoint ):
862
870
self .assertEqual (point .count , 1 )
863
871
if metric .name == "http.server.request.duration" :
864
- self .assertAlmostEqual (duration_s * 0.1 , point .sum , places = 1 )
872
+ self .assertAlmostEqual (
873
+ duration_s * 0.1 , point .sum , places = 1
874
+ )
865
875
elif metric .name == "http.server.response.body.size" :
866
876
self .assertEqual (response_size , point .sum )
867
877
elif metric .name == "http.server.request.body.size" :
@@ -887,7 +897,9 @@ def test_basic_post_request_metric_success_both_semconv(self):
887
897
if isinstance (point , HistogramDataPoint ):
888
898
self .assertEqual (point .count , 1 )
889
899
if metric .name == "http.server.request.duration" :
890
- self .assertAlmostEqual (duration_s * 0.1 , point .sum , places = 1 )
900
+ self .assertAlmostEqual (
901
+ duration_s * 0.1 , point .sum , places = 1
902
+ )
891
903
elif metric .name == "http.server.response.body.size" :
892
904
self .assertEqual (response_size , point .sum )
893
905
elif metric .name == "http.server.request.body.size" :
@@ -1069,6 +1081,18 @@ def test_uninstrument_after_instrument(self):
1069
1081
spans = self .memory_exporter .get_finished_spans ()
1070
1082
self .assertEqual (len (spans ), 3 )
1071
1083
1084
+ def test_no_op_tracer_provider (self ):
1085
+ self ._instrumentor .uninstrument ()
1086
+ self ._instrumentor .instrument (
1087
+ tracer_provider = trace .NoOpTracerProvider ()
1088
+ )
1089
+
1090
+ app = self ._create_fastapi_app ()
1091
+ client = TestClient (app )
1092
+ client .get ("/foobar" )
1093
+ spans = self .memory_exporter .get_finished_spans ()
1094
+ self .assertEqual (len (spans ), 0 )
1095
+
1072
1096
def tearDown (self ):
1073
1097
self ._instrumentor .uninstrument ()
1074
1098
super ().tearDown ()
@@ -1758,4 +1782,4 @@ def test_custom_header_not_present_in_non_recording_span(self):
1758
1782
)
1759
1783
self .assertEqual (200 , resp .status_code )
1760
1784
span_list = self .memory_exporter .get_finished_spans ()
1761
- self .assertEqual (len (span_list ), 0 )
1785
+ self .assertEqual (len (span_list ), 0 )
0 commit comments