Skip to content

Commit e9fed7d

Browse files
committed
fix(flask): wrap wsgi_app call in try/except to prevent active_requests gauge leak
If wsgi_app() raises an uncaught exception, the active_requests_counter decrement at the end of _wrapped_app was never reached, causing the gauge to permanently read high. Kubernetes HPA and similar systems would see phantom load. Add a bare try/except that decrements the counter and re-raises on exception, matching the pattern already used in the WSGI instrumentation. Fixes #4431 Signed-off-by: alliasgher <alliasgher123@gmail.com>
1 parent a912524 commit e9fed7d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

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

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,11 @@ def _start_response(status, response_headers, *args, **kwargs):
415415
response_hook(span, status, response_headers)
416416
return start_response(status, response_headers, *args, **kwargs)
417417

418-
result = wsgi_app(wrapped_app_environ, _start_response)
418+
try:
419+
result = wsgi_app(wrapped_app_environ, _start_response)
420+
except Exception:
421+
active_requests_counter.add(-1, active_requests_count_attrs)
422+
raise
419423

420424
# Note: Streaming response context cleanup is now handled in the Flask teardown function
421425
# (_wrapped_teardown_request) to ensure proper cleanup following Logfire's recommendations

0 commit comments

Comments
 (0)