@@ -145,6 +145,43 @@ def test_starlette_metrics(self):
145
145
attr , _recommended_attrs [metric .name ]
146
146
)
147
147
self .assertTrue (number_data_point_seen and histogram_data_point_seen )
148
+
149
+ def test_basic_post_request_metric_success (self ):
150
+ start = default_timer ()
151
+ self ._client .post ("/foobar" )
152
+ duration = max (round ((default_timer () - start ) * 1000 ), 0 )
153
+ metrics_list = self .memory_metrics_reader .get_metrics_data ()
154
+ for metric in (
155
+ metrics_list .resource_metrics [0 ].scope_metrics [0 ].metrics
156
+ ):
157
+ for point in list (metric .data .data_points ):
158
+ if isinstance (point , HistogramDataPoint ):
159
+ self .assertEqual (point .count , 1 )
160
+ self .assertAlmostEqual (duration , point .sum , delta = 30 )
161
+ if isinstance (point , NumberDataPoint ):
162
+ self .assertEqual (point .value , 0 )
163
+
164
+ def test_metric_uninstrument (self ):
165
+ # instrumenting class and creating app to send request
166
+ self ._instrumentor .instrument ()
167
+ app = self ._create_starlette_app ()
168
+ client = TestClient (app )
169
+ client .get ("/foobar" )
170
+ # uninstrumenting class and creating the app again
171
+ self ._instrumentor .uninstrument ()
172
+ app = self ._create_starlette_app ()
173
+ client = TestClient (app )
174
+ client .get ("/foobar" )
175
+
176
+ metrics_list = self .memory_metrics_reader .get_metrics_data ()
177
+ for metric in (
178
+ metrics_list .resource_metrics [0 ].scope_metrics [0 ].metrics
179
+ ):
180
+ for point in list (metric .data .data_points ):
181
+ if isinstance (point , HistogramDataPoint ):
182
+ self .assertEqual (point .count , 1 )
183
+ if isinstance (point , NumberDataPoint ):
184
+ self .assertEqual (point .value , 0 )
148
185
149
186
@staticmethod
150
187
def _create_starlette_app ():
0 commit comments