@@ -202,6 +202,13 @@ def client_resposne_hook(span, future):
202
202
_OTEL_PATCHED_KEY = "_otel_patched_key"
203
203
204
204
_START_TIME = "start_time"
205
+ _CLIENT_DURATION_HISTOGRAM = "http.client.duration"
206
+ _CLIENT_REQUEST_SIZE_HISTOGRAM = "http.client.request.size"
207
+ _CLIENT_RESPONSE_SIZE_HISTOGRAM = "http.client.response.size"
208
+ _SERVER_DURATION_HISTOGRAM = "http.server.duration"
209
+ _SERVER_REQUEST_SIZE_HISTOGRAM = "http.server.request.size"
210
+ _SERVER_RESPONSE_SIZE_HISTOGRAM = "http.server.response.size"
211
+ _SERVER_ACTIVE_REQUESTS_HISTOGRAM = "http.server.active_requests"
205
212
206
213
_excluded_urls = get_excluded_urls ("TORNADO" )
207
214
_traced_request_attrs = get_traced_request_attrs ("TORNADO" )
@@ -267,9 +274,9 @@ def handler_init(init, handler, args, kwargs):
267
274
tracer ,
268
275
client_request_hook ,
269
276
client_response_hook ,
270
- client_histograms [MetricInstruments . HTTP_CLIENT_DURATION ],
271
- client_histograms [MetricInstruments . HTTP_CLIENT_REQUEST_SIZE ],
272
- client_histograms [MetricInstruments . HTTP_CLIENT_RESPONSE_SIZE ],
277
+ client_histograms [_CLIENT_DURATION_HISTOGRAM ],
278
+ client_histograms [_CLIENT_REQUEST_SIZE_HISTOGRAM ],
279
+ client_histograms [_CLIENT_RESPONSE_SIZE_HISTOGRAM ],
273
280
),
274
281
)
275
282
@@ -283,23 +290,23 @@ def _uninstrument(self, **kwargs):
283
290
284
291
def _create_server_histograms (meter ) -> Dict [str , Histogram ]:
285
292
histograms = {
286
- MetricInstruments . HTTP_SERVER_DURATION : meter .create_histogram (
287
- name = MetricInstruments . HTTP_SERVER_DURATION ,
293
+ _SERVER_DURATION_HISTOGRAM : meter .create_histogram (
294
+ name = "http.server.duration" ,
288
295
unit = "ms" ,
289
296
description = "measures the duration outbound HTTP requests" ,
290
297
),
291
- MetricInstruments . HTTP_SERVER_REQUEST_SIZE : meter .create_histogram (
292
- name = MetricInstruments . HTTP_SERVER_REQUEST_SIZE ,
298
+ _SERVER_REQUEST_SIZE_HISTOGRAM : meter .create_histogram (
299
+ name = "http.server.request.size" ,
293
300
unit = "By" ,
294
301
description = "measures the size of HTTP request messages (compressed)" ,
295
302
),
296
- MetricInstruments . HTTP_SERVER_RESPONSE_SIZE : meter .create_histogram (
297
- name = MetricInstruments . HTTP_SERVER_RESPONSE_SIZE ,
303
+ _SERVER_RESPONSE_SIZE_HISTOGRAM : meter .create_histogram (
304
+ name = "http.server.response.size" ,
298
305
unit = "By" ,
299
306
description = "measures the size of HTTP response messages (compressed)" ,
300
307
),
301
- MetricInstruments . HTTP_SERVER_ACTIVE_REQUESTS : meter .create_up_down_counter (
302
- name = MetricInstruments . HTTP_SERVER_ACTIVE_REQUESTS ,
308
+ _SERVER_ACTIVE_REQUESTS_HISTOGRAM : meter .create_up_down_counter (
309
+ name = "http.server.active_requests" ,
303
310
unit = "requests" ,
304
311
description = "measures the number of concurrent HTTP requests that are currently in-flight" ,
305
312
),
@@ -310,18 +317,18 @@ def _create_server_histograms(meter) -> Dict[str, Histogram]:
310
317
311
318
def _create_client_histograms (meter ) -> Dict [str , Histogram ]:
312
319
histograms = {
313
- MetricInstruments . HTTP_CLIENT_DURATION : meter .create_histogram (
314
- name = MetricInstruments . HTTP_CLIENT_DURATION ,
320
+ _CLIENT_DURATION_HISTOGRAM : meter .create_histogram (
321
+ name = "http.client.duration" ,
315
322
unit = "ms" ,
316
323
description = "measures the duration outbound HTTP requests" ,
317
324
),
318
- MetricInstruments . HTTP_CLIENT_REQUEST_SIZE : meter .create_histogram (
319
- name = MetricInstruments . HTTP_CLIENT_REQUEST_SIZE ,
325
+ _CLIENT_REQUEST_SIZE_HISTOGRAM : meter .create_histogram (
326
+ name = "http.client.request.size" ,
320
327
unit = "By" ,
321
328
description = "measures the size of HTTP request messages (compressed)" ,
322
329
),
323
- MetricInstruments . HTTP_CLIENT_RESPONSE_SIZE : meter .create_histogram (
324
- name = MetricInstruments . HTTP_CLIENT_RESPONSE_SIZE ,
330
+ _CLIENT_RESPONSE_SIZE_HISTOGRAM : meter .create_histogram (
331
+ name = "http.client.response.size" ,
325
332
unit = "By" ,
326
333
description = "measures the size of HTTP response messages (compressed)" ,
327
334
),
@@ -556,14 +563,14 @@ def _record_prepare_metrics(server_histograms, handler):
556
563
request_size = int (handler .request .headers .get ("Content-Length" , 0 ))
557
564
metric_attributes = _create_metric_attributes (handler )
558
565
559
- server_histograms [MetricInstruments . HTTP_SERVER_REQUEST_SIZE ].record (
566
+ server_histograms [_SERVER_REQUEST_SIZE_HISTOGRAM ].record (
560
567
request_size , attributes = metric_attributes
561
568
)
562
569
563
570
active_requests_attributes = _create_active_requests_attributes (
564
571
handler .request
565
572
)
566
- server_histograms [MetricInstruments . HTTP_SERVER_ACTIVE_REQUESTS ].add (
573
+ server_histograms [_SERVER_ACTIVE_REQUESTS_HISTOGRAM ].add (
567
574
1 , attributes = active_requests_attributes
568
575
)
569
576
@@ -579,18 +586,18 @@ def _record_on_finish_metrics(server_histograms, handler, error=None):
579
586
if isinstance (error , tornado .web .HTTPError ):
580
587
metric_attributes [SpanAttributes .HTTP_STATUS_CODE ] = error .status_code
581
588
582
- server_histograms [MetricInstruments . HTTP_SERVER_RESPONSE_SIZE ].record (
589
+ server_histograms [_SERVER_RESPONSE_SIZE_HISTOGRAM ].record (
583
590
response_size , attributes = metric_attributes
584
591
)
585
592
586
- server_histograms [MetricInstruments . HTTP_SERVER_DURATION ].record (
593
+ server_histograms [_SERVER_DURATION_HISTOGRAM ].record (
587
594
elapsed_time , attributes = metric_attributes
588
595
)
589
596
590
597
active_requests_attributes = _create_active_requests_attributes (
591
598
handler .request
592
599
)
593
- server_histograms [MetricInstruments . HTTP_SERVER_ACTIVE_REQUESTS ].add (
600
+ server_histograms [_SERVER_ACTIVE_REQUESTS_HISTOGRAM ].add (
594
601
- 1 , attributes = active_requests_attributes
595
602
)
596
603
0 commit comments