Skip to content

Commit 252b89f

Browse files
authored
Refactor request teardown to avoid duplicate cleanup
Remove redundant environment variable cleanup in finally block.
1 parent 4cb5c5e commit 252b89f

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask

instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ def _teardown_request(exc):
643643

644644
if token:
645645
context.detach(token)
646+
flask.request.environ.pop(_ENVIRON_ACTIVATION_KEY, None)
647+
flask.request.environ.pop(_ENVIRON_TOKEN, None)
646648

647649
except (RuntimeError, AttributeError, ValueError) as teardown_exc:
648650
# Log the error but don't raise it to avoid breaking the request handling
@@ -651,9 +653,6 @@ def _teardown_request(exc):
651653
teardown_exc,
652654
exc_info=True,
653655
)
654-
finally:
655-
flask.request.environ.pop(_ENVIRON_ACTIVATION_KEY, None)
656-
flask.request.environ.pop(_ENVIRON_TOKEN, None)
657656

658657
return _teardown_request
659658

0 commit comments

Comments
 (0)