@@ -164,7 +164,7 @@ def setUp(self):
164164 self .env_patch = patch .dict (
165165 "os.environ" ,
166166 {
167- "OTEL_PYTHON_FLASK_EXCLUDED_URLS" : "http://localhost/env_excluded_arg/123,env_excluded_noarg" ,
167+ "OTEL_PYTHON_FLASK_EXCLUDED_URLS" : "http://localhost/env_excluded_arg/123,env_excluded_noarg,env_excluded_arg/789 " ,
168168 OTEL_SEMCONV_STABILITY_OPT_IN : sem_conv_mode ,
169169 },
170170 )
@@ -736,6 +736,80 @@ def test_metric_uninstrument(self):
736736 if isinstance (point , HistogramDataPoint ):
737737 self .assertEqual (point .count , 1 )
738738
739+ def test_flask_metrics_excluded_urls (self ):
740+ start = default_timer ()
741+ self .client .get ("/env_excluded_arg/123" )
742+ self .client .get ("/env_excluded_noarg" )
743+ self .client .get ("/env_excluded_arg/789" )
744+ duration = max (round ((default_timer () - start ) * 1000 ), 0 )
745+ metrics_list = self .memory_metrics_reader .get_metrics_data ()
746+ number_data_point_seen = False
747+ histogram_data_point_seen = False
748+ self .assertTrue (len (metrics_list .resource_metrics ) != 0 )
749+ for resource_metric in metrics_list .resource_metrics :
750+ self .assertTrue (len (resource_metric .scope_metrics ) != 0 )
751+ for scope_metric in resource_metric .scope_metrics :
752+ self .assertTrue (len (scope_metric .metrics ) != 0 )
753+ for metric in scope_metric .metrics :
754+ self .assertIn (metric .name , _expected_metric_names_old )
755+ data_points = list (metric .data .data_points )
756+ self .assertEqual (len (data_points ), 1 )
757+ for point in data_points :
758+ if isinstance (point , HistogramDataPoint ):
759+ self .assertEqual (point .count , 0 )
760+ self .assertAlmostEqual (
761+ duration , point .sum , delta = 10
762+ )
763+ histogram_data_point_seen = True
764+ if isinstance (point , NumberDataPoint ):
765+ number_data_point_seen = True
766+ for attr in point .attributes :
767+ self .assertIn (
768+ attr ,
769+ _recommended_metrics_attrs_old [metric .name ],
770+ )
771+ self .assertTrue (number_data_point_seen )
772+ self .assertFalse (histogram_data_point_seen )
773+
774+ def test_flask_metrics_excluded_urls_new_semconv (self ):
775+ start = default_timer ()
776+ self .client .get ("/env_excluded_arg/123" )
777+ self .client .get ("/env_excluded_noarg" )
778+ self .client .get ("/env_excluded_arg/789" )
779+ duration_s = max (default_timer () - start , 0 )
780+ metrics_list = self .memory_metrics_reader .get_metrics_data ()
781+ number_data_point_seen = False
782+ histogram_data_point_seen = False
783+ self .assertTrue (len (metrics_list .resource_metrics ) != 0 )
784+ for resource_metric in metrics_list .resource_metrics :
785+ self .assertTrue (len (resource_metric .scope_metrics ) != 0 )
786+ for scope_metric in resource_metric .scope_metrics :
787+ self .assertTrue (len (scope_metric .metrics ) != 0 )
788+ for metric in scope_metric .metrics :
789+ self .assertIn (metric .name , _expected_metric_names_new )
790+ data_points = list (metric .data .data_points )
791+ self .assertEqual (len (data_points ), 1 )
792+ for point in data_points :
793+ if isinstance (point , HistogramDataPoint ):
794+ self .assertEqual (point .count , 0 )
795+ self .assertAlmostEqual (
796+ duration_s , point .sum , places = 1
797+ )
798+ self .assertEqual (
799+ point .explicit_bounds ,
800+ HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
801+ )
802+ histogram_data_point_seen = True
803+ if isinstance (point , NumberDataPoint ):
804+ number_data_point_seen = True
805+ for attr in point .attributes :
806+ self .assertIn (
807+ attr ,
808+ _recommended_metrics_attrs_new [metric .name ],
809+ )
810+ self .assertTrue (number_data_point_seen )
811+ self .assertFalse (histogram_data_point_seen )
812+
739813
740814class TestProgrammaticHooks (InstrumentationTest , WsgiTestBase ):
741815 def setUp (self ):
0 commit comments