Skip to content

Commit cd7b481

Browse files
Allow stack traces in HTTP responses only if INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE is enabled (#12938)
1 parent c1d19e2 commit cd7b481

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

localstack-core/localstack/aws/handlers/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def create_exception_response(self, exception: Exception, context: RequestContex
184184
if not self.handle_internal_failures:
185185
return
186186

187-
if config.DEBUG:
187+
if config.INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE:
188188
exception = "".join(
189189
traceback.format_exception(
190190
type(exception), value=exception, tb=exception.__traceback__

localstack-core/localstack/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,9 @@ def populate_edge_configuration(
823823
# Flag to enable the validation of the requests made to the LocalStack internal endpoints. Active by default.
824824
OPENAPI_VALIDATE_REQUEST = is_env_true("OPENAPI_VALIDATE_REQUEST")
825825

826+
# environment variable to determine whether to include stack traces in http responses
827+
INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE = is_env_true("INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE")
828+
826829
# whether to skip waiting for the infrastructure to shut down, or exit immediately
827830
FORCE_SHUTDOWN = is_env_not_false("FORCE_SHUTDOWN")
828831

localstack-core/localstack/testing/pytest/in_memory_localstack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def pytest_runtestloop(session: Session):
7171

7272
# configure
7373
os.environ[ENV_INTERNAL_TEST_RUN] = "1"
74+
localstack_config.INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE = True
75+
7476
safe_requests.verify_ssl = False
7577

7678
from localstack.runtime import current

tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import os
22

33
import pytest
4+
from _pytest.monkeypatch import MonkeyPatch
5+
6+
from localstack import config
47

58
os.environ["LOCALSTACK_INTERNAL_TEST_RUN"] = "1"
69

@@ -87,3 +90,16 @@ def secondary_aws_client(secondary_aws_client_factory):
8790
from localstack.testing.aws.util import base_testing_aws_client
8891

8992
return base_testing_aws_client(secondary_aws_client_factory)
93+
94+
95+
@pytest.fixture(scope="session", autouse=True)
96+
def enable_stack_trace_for_tests():
97+
"""
98+
Ensure stack traces are enabled in HTTP responses during test sessions.
99+
100+
This is useful for debugging purposes.
101+
"""
102+
mpatch = MonkeyPatch()
103+
mpatch.setattr(config, "INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE", True)
104+
yield mpatch
105+
mpatch.undo()

0 commit comments

Comments
 (0)