@@ -84,3 +84,50 @@ def assert_success_span(
84
84
"net.peer.ip" : self .assert_ip ,
85
85
}
86
86
self .assertGreaterEqual (span .attributes .items (), attributes .items ())
87
+
88
+ class TestURLLib3InstrumentorMetric (HttpTestBase , TestBase ):
89
+
90
+ def setUp (self ):
91
+ super ().setUp ()
92
+ self .assert_ip = self .server .server_address [0 ]
93
+ self .assert_port = self .server .server_address [1 ]
94
+ self .http_host = ":" .join (map (str , self .server .server_address [:2 ]))
95
+ self .http_url_base = "http://" + self .http_host
96
+ self .http_url = self .http_url_base + "/status/200"
97
+ URLLib3Instrumentor ().instrument (meter_provider = self .meter_provider )
98
+
99
+ def tearDown (self ):
100
+ super ().tearDown ()
101
+ URLLib3Instrumentor ().uninstrument ()
102
+
103
+ @staticmethod
104
+ def perform_request (url : str ) -> urllib3 .response .HTTPResponse :
105
+ with urllib3 .PoolManager () as pool :
106
+ resp = pool .request ("GET" , url )
107
+ resp .close ()
108
+ return resp
109
+
110
+ def test_basic_metric_success (self ):
111
+ with urllib3 .HTTPConnectionPool (self .http_host , timeout = 3 ) as pool :
112
+ response = pool .request ("GET" , "/status/200" ,fields = {"data" :"test" })
113
+
114
+ expected_attributes = {
115
+ "http.status_code" : 200 ,
116
+ "http.host" : self .assert_ip ,
117
+ "http.method" : "GET" ,
118
+ "http.flavor" : "1.1" ,
119
+ "http.scheme" : "http" ,
120
+ 'net.peer.name' : self .assert_ip ,
121
+ 'net.peer.port' : self .assert_port
122
+ }
123
+
124
+ resource_metrics = self .memory_metrics_reader .get_metrics_data ().resource_metrics
125
+ for metrics in resource_metrics :
126
+ for scope_metrics in metrics .scope_metrics :
127
+ self .assertEqual (len (scope_metrics .metrics ), 3 )
128
+ for metric in scope_metrics .metrics :
129
+ for data_point in metric .data .data_points :
130
+ self .assertDictEqual (
131
+ expected_attributes , dict (data_point .attributes )
132
+ )
133
+ self .assertEqual (data_point .count , 1 )
0 commit comments