@@ -374,10 +374,6 @@ def _wrapped_app(wrapped_app_environ, start_response):
374374 attributes = otel_wsgi .collect_request_attributes (
375375 wrapped_app_environ , sem_conv_opt_in_mode
376376 )
377- # Enhance attributes with custom labeler attributes
378- attributes = enhance_metric_attributes (
379- attributes , wrapped_app_environ , "request"
380- )
381377 active_requests_count_attrs = (
382378 otel_wsgi ._parse_active_request_count_attrs (
383379 attributes ,
@@ -445,6 +441,11 @@ def _start_response(status, response_headers, *args, **kwargs):
445441 request_route
446442 )
447443
444+ # Enhance attributes with any custom labeler attributes
445+ duration_attrs_old = enhance_metric_attributes (
446+ duration_attrs_old
447+ )
448+
448449 duration_histogram_old .record (
449450 max (round (duration_s * 1000 ), 0 ), duration_attrs_old
450451 )
@@ -456,6 +457,11 @@ def _start_response(status, response_headers, *args, **kwargs):
456457 if request_route :
457458 duration_attrs_new [HTTP_ROUTE ] = str (request_route )
458459
460+ # Enhance attributes with any custom labeler attributes
461+ duration_attrs_new = enhance_metric_attributes (
462+ duration_attrs_new
463+ )
464+
459465 duration_histogram_new .record (
460466 max (duration_s , 0 ), duration_attrs_new
461467 )
@@ -485,7 +491,7 @@ def _before_request():
485491 )
486492 # Enhance attributes with custom labeler attributes
487493 attributes = enhance_metric_attributes (
488- attributes , flask_request_environ , "request"
494+ attributes
489495 )
490496 if flask .request .url_rule :
491497 # For 404 that result from no route found, etc, we
0 commit comments