4040 OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS ,
4141 OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST ,
4242 OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE ,
43+ OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE ,
44+ OTEL_PYTHON_INSTRUMENTATION_HTTP_CAPTURE_ALL_METHODS ,
4345 get_excluded_urls ,
4446)
4547
@@ -326,6 +328,25 @@ def test_flask_metric_values(self):
326328 if isinstance (point , NumberDataPoint ):
327329 self .assertEqual (point .value , 0 )
328330
331+ def _assert_basic_metric (self , expected_duration_attributes , expected_requests_count_attributes ):
332+ metrics_list = self .memory_metrics_reader .get_metrics_data ()
333+ for resource_metric in metrics_list .resource_metrics :
334+ for scope_metrics in resource_metric .scope_metrics :
335+ for metric in scope_metrics .metrics :
336+ for point in list (metric .data .data_points ):
337+ if isinstance (point , HistogramDataPoint ):
338+ self .assertDictEqual (
339+ expected_duration_attributes ,
340+ dict (point .attributes ),
341+ )
342+ self .assertEqual (point .count , 1 )
343+ elif isinstance (point , NumberDataPoint ):
344+ self .assertDictEqual (
345+ expected_requests_count_attributes ,
346+ dict (point .attributes ),
347+ )
348+ self .assertEqual (point .value , 0 )
349+
329350 def test_basic_metric_success (self ):
330351 self .client .get ("/hello/756" )
331352 expected_duration_attributes = {
@@ -344,23 +365,62 @@ def test_basic_metric_success(self):
344365 "http.flavor" : "1.1" ,
345366 "http.server_name" : "localhost" ,
346367 }
347- metrics_list = self .memory_metrics_reader .get_metrics_data ()
348- for resource_metric in metrics_list .resource_metrics :
349- for scope_metrics in resource_metric .scope_metrics :
350- for metric in scope_metrics .metrics :
351- for point in list (metric .data .data_points ):
352- if isinstance (point , HistogramDataPoint ):
353- self .assertDictEqual (
354- expected_duration_attributes ,
355- dict (point .attributes ),
356- )
357- self .assertEqual (point .count , 1 )
358- elif isinstance (point , NumberDataPoint ):
359- self .assertDictEqual (
360- expected_requests_count_attributes ,
361- dict (point .attributes ),
362- )
363- self .assertEqual (point .value , 0 )
368+ self ._assert_basic_metric (
369+ expected_duration_attributes ,
370+ expected_requests_count_attributes ,
371+ )
372+
373+ def test_basic_metric_nonstandard_http_method_success (self ):
374+ self .client .open ("/hello/756" , method = "NONSTANDARD" )
375+ expected_duration_attributes = {
376+ "http.method" : "UNKNOWN" ,
377+ "http.host" : "localhost" ,
378+ "http.scheme" : "http" ,
379+ "http.flavor" : "1.1" ,
380+ "http.server_name" : "localhost" ,
381+ "net.host.port" : 80 ,
382+ "http.status_code" : 405 ,
383+ }
384+ expected_requests_count_attributes = {
385+ "http.method" : "UNKNOWN" ,
386+ "http.host" : "localhost" ,
387+ "http.scheme" : "http" ,
388+ "http.flavor" : "1.1" ,
389+ "http.server_name" : "localhost" ,
390+ }
391+ self ._assert_basic_metric (
392+ expected_duration_attributes ,
393+ expected_requests_count_attributes ,
394+ )
395+
396+ @patch .dict (
397+ "os.environ" ,
398+ {
399+ OTEL_PYTHON_INSTRUMENTATION_HTTP_CAPTURE_ALL_METHODS : "1" ,
400+ },
401+ )
402+ def test_basic_metric_nonstandard_http_method_allowed_success (self ):
403+ self .client .open ("/hello/756" , method = "NONSTANDARD" )
404+ expected_duration_attributes = {
405+ "http.method" : "NONSTANDARD" ,
406+ "http.host" : "localhost" ,
407+ "http.scheme" : "http" ,
408+ "http.flavor" : "1.1" ,
409+ "http.server_name" : "localhost" ,
410+ "net.host.port" : 80 ,
411+ "http.status_code" : 405 ,
412+ }
413+ expected_requests_count_attributes = {
414+ "http.method" : "NONSTANDARD" ,
415+ "http.host" : "localhost" ,
416+ "http.scheme" : "http" ,
417+ "http.flavor" : "1.1" ,
418+ "http.server_name" : "localhost" ,
419+ }
420+ self ._assert_basic_metric (
421+ expected_duration_attributes ,
422+ expected_requests_count_attributes ,
423+ )
364424
365425 def test_metric_uninstrument (self ):
366426 self .client .delete ("/hello/756" )
0 commit comments