@@ -180,32 +180,24 @@ def test_starlette_metrics(self):
180180 self ._client .get ("/foobar" )
181181 self ._client .get ("/foobar" )
182182 self ._client .get ("/foobar" )
183- metrics_list = self .memory_metrics_reader .get_metrics_data ()
184183 number_data_point_seen = False
185184 histogram_data_point_seen = False
186- self .assertTrue (len (metrics_list .resource_metrics ) == 1 )
187- for resource_metric in metrics_list .resource_metrics :
188- self .assertTrue (len (resource_metric .scope_metrics ) == 1 )
189- for scope_metric in resource_metric .scope_metrics :
190- self .assertEqual (
191- scope_metric .scope .name ,
192- "opentelemetry.instrumentation.starlette" ,
193- )
194- self .assertTrue (len (scope_metric .metrics ) == 3 )
195- for metric in scope_metric .metrics :
196- self .assertIn (metric .name , _expected_metric_names )
197- data_points = list (metric .data .data_points )
198- self .assertEqual (len (data_points ), 1 )
199- for point in data_points :
200- if isinstance (point , HistogramDataPoint ):
201- self .assertEqual (point .count , 3 )
202- histogram_data_point_seen = True
203- if isinstance (point , NumberDataPoint ):
204- number_data_point_seen = True
205- for attr in point .attributes :
206- self .assertIn (
207- attr , _recommended_attrs [metric .name ]
208- )
185+ metrics = self .get_sorted_metrics (
186+ scope = "opentelemetry.instrumentation.starlette"
187+ )
188+ self .assertTrue (len (metrics ) == 3 )
189+ for metric in metrics :
190+ self .assertIn (metric .name , _expected_metric_names )
191+ data_points = list (metric .data .data_points )
192+ self .assertEqual (len (data_points ), 1 )
193+ for point in data_points :
194+ if isinstance (point , HistogramDataPoint ):
195+ self .assertEqual (point .count , 3 )
196+ histogram_data_point_seen = True
197+ if isinstance (point , NumberDataPoint ):
198+ number_data_point_seen = True
199+ for attr in point .attributes :
200+ self .assertIn (attr , _recommended_attrs [metric .name ])
209201 self .assertTrue (number_data_point_seen and histogram_data_point_seen )
210202
211203 def test_basic_post_request_metric_success (self ):
@@ -233,10 +225,10 @@ def test_basic_post_request_metric_success(self):
233225 duration = max (round ((default_timer () - start ) * 1000 ), 0 )
234226 response_size = int (response .headers .get ("content-length" ))
235227 request_size = int (response .request .headers .get ("content-length" ))
236- metrics_list = self .memory_metrics_reader . get_metrics_data ()
237- for metric in (
238- metrics_list . resource_metrics [ 0 ]. scope_metrics [ 0 ]. metrics
239- ) :
228+ metrics = self .get_sorted_metrics (
229+ scope = "opentelemetry.instrumentation.starlette"
230+ )
231+ for metric in metrics :
240232 for point in list (metric .data .data_points ):
241233 if isinstance (point , HistogramDataPoint ):
242234 self .assertEqual (point .count , 1 )
@@ -262,10 +254,10 @@ def test_metric_for_uninstrment_app_method(self):
262254 self ._instrumentor .uninstrument_app (self ._app )
263255 self ._client .get ("/foobar" )
264256 self ._client .get ("/foobar" )
265- metrics_list = self .memory_metrics_reader . get_metrics_data ()
266- for metric in (
267- metrics_list . resource_metrics [ 0 ]. scope_metrics [ 0 ]. metrics
268- ) :
257+ metrics = self .get_sorted_metrics (
258+ scope = "opentelemetry.instrumentation.starlette"
259+ )
260+ for metric in metrics :
269261 for point in list (metric .data .data_points ):
270262 if isinstance (point , HistogramDataPoint ):
271263 self .assertEqual (point .count , 1 )
@@ -283,10 +275,10 @@ def test_metric_uninstrument_inherited_by_base(self):
283275 client .get ("/foobar" )
284276 client .get ("/foobar" )
285277 client .get ("/foobar" )
286- metrics_list = self .memory_metrics_reader . get_metrics_data ()
287- for metric in (
288- metrics_list . resource_metrics [ 0 ]. scope_metrics [ 0 ]. metrics
289- ) :
278+ metrics = self .get_sorted_metrics (
279+ scope = "opentelemetry.instrumentation.starlette"
280+ )
281+ for metric in metrics :
290282 for point in list (metric .data .data_points ):
291283 if isinstance (point , HistogramDataPoint ):
292284 self .assertEqual (point .count , 1 )
0 commit comments