@@ -285,7 +285,6 @@ def response_hook(span: Span, status: str, response_headers: List):
285
285
_ENVIRON_ACTIVATION_KEY = "opentelemetry-flask.activation_key"
286
286
_ENVIRON_REQCTX_REF_KEY = "opentelemetry-flask.reqctx_ref_key"
287
287
_ENVIRON_TOKEN = "opentelemetry-flask.token"
288
- _ENVIRON_REQUEST_ROUTE_KEY = "opentelemetry-flask.request-route_key"
289
288
290
289
_excluded_urls_from_env = get_excluded_urls ("FLASK" )
291
290
@@ -342,16 +341,16 @@ def _wrapped_app(wrapped_app_environ, start_response):
342
341
)
343
342
344
343
active_requests_counter .add (1 , active_requests_count_attrs )
344
+ request_route = None
345
345
346
346
def _start_response (status , response_headers , * args , ** kwargs ):
347
347
if flask .request and (
348
348
excluded_urls is None
349
349
or not excluded_urls .url_disabled (flask .request .url )
350
350
):
351
351
if flask .request .url_rule :
352
- wrapped_app_environ [_ENVIRON_REQUEST_ROUTE_KEY ] = str (
353
- flask .request .url_rule
354
- )
352
+ nonlocal request_route
353
+ request_route = str (flask .request .url_rule )
355
354
356
355
span = flask .request .environ .get (_ENVIRON_SPAN_KEY )
357
356
@@ -396,10 +395,9 @@ def _start_response(status, response_headers, *args, **kwargs):
396
395
attributes , _HTTPStabilityMode .DEFAULT
397
396
)
398
397
399
- if wrapped_app_environ .get (_ENVIRON_REQUEST_ROUTE_KEY , None ):
400
- duration_attrs_old [SpanAttributes .HTTP_TARGET ] = (
401
- wrapped_app_environ .get (_ENVIRON_REQUEST_ROUTE_KEY )
402
- )
398
+ if request_route :
399
+ duration_attrs_old [SpanAttributes .HTTP_TARGET ] = request_route
400
+
403
401
duration_histogram_old .record (
404
402
max (round (duration_s * 1000 ), 0 ), duration_attrs_old
405
403
)
@@ -408,10 +406,8 @@ def _start_response(status, response_headers, *args, **kwargs):
408
406
attributes , _HTTPStabilityMode .HTTP
409
407
)
410
408
411
- if wrapped_app_environ .get (_ENVIRON_REQUEST_ROUTE_KEY , None ):
412
- duration_attrs_new [HTTP_ROUTE ] = wrapped_app_environ .get (
413
- _ENVIRON_REQUEST_ROUTE_KEY
414
- )
409
+ if request_route :
410
+ duration_attrs_new [HTTP_ROUTE ] = request_route
415
411
416
412
duration_histogram_new .record (
417
413
max (duration_s , 0 ), duration_attrs_new
0 commit comments