-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Allow stack traces in HTTP responses only if INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE
is enabled
#12938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Currently, only patch changes are allowed on main. Your PR labels (semver: minor) indicate that it cannot be merged into the main at this time. |
1 similar comment
Currently, only patch changes are allowed on main. Your PR labels (semver: minor) indicate that it cannot be merged into the main at this time. |
Test Results (amd64) - Integration, Bootstrap 5 files 5 suites 2h 20m 29s ⏱️ Results for commit df061e4. ♻️ This comment has been updated with latest results. |
LocalStack Community integration with Pro 2 files ±0 2 suites ±0 1h 42m 29s ⏱️ - 1m 53s Results for commit df061e4. ± Comparison against base commit 2d08a27. This pull request removes 1 and adds 3 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
general question: if we remove this, how does the devx look like for localstack developers? the stacktrace is added when DEBUG=1
is set so the stack traces appear in test failures directly, which has helped (at least me) in the past to find issues very quickly.
That's a good point: it returns the error directly in the client call, which allows the test annotation to show the error directly and not have to go through the logs of the running LocalStack instance. I think there's a fine line with the customer running with |
that's fair. so perhaps instead of removing the behavior (returning stack traces) all together, we could tie it to our tests being run. for example |
S3 Image Test Results (AMD64 / ARM64) 2 files 2 suites 8m 52s ⏱️ Results for commit df061e4. ♻️ This comment has been updated with latest results. |
f103562
to
5c4c022
Compare
5c4c022
to
0fde5fd
Compare
INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE
is enabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question regarding adding the flag to our config.py
file instead of directly manipulating environment variables, not sure if I miss some context. Maybe it is because it is internal only?
For the other "test only" variables like LOCALSTACK_INTERNAL_TEST_RUN
and LOCALSTACK_INTERNAL_TEST_COLLECT_METRIC
, they don't change LocalStack behavior, only the tests behavior, which is maybe why they are not added to config.py
.
Here we're directly directing LocalStack behavior, so I think we might be better if it is a proper config flag, what do you think?
As a side-note, it could also allow us to keep the current behavior until the next release (where we would only flip the flag) to not modify behavior suddenly, but to be honest I'm not sure it is worth it, I don't see what it would bring to our users, so I think we can change it in latest
😄
if ( | ||
os.environ.get(constants.INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE) | ||
in constants.TRUE_STRINGS | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: was there a specify reason that would prevent us from adding INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE
to config like other configuration variables? It would more easily discoverable, and we could still patch it in the fixture with monkeypatch.setattr(config, "INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE", True)
But maybe I am missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for raising this 🙌 There was no strong reason not to add it to config.py
, the flag was introduced mainly for internal use so took this approach. But I agree that making it a proper config flag would improve discoverability also since this flag affects the LocalStack behaviour. I will go ahead and move it to config.py
with a default of 0
, and patch it to 1
in the fixture and also make relevant changes in pro 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
tests/conftest.py
Outdated
@pytest.fixture(autouse=True) | ||
def enable_stack_trace_for_tests(monkeypatch): | ||
""" | ||
Ensure stack traces are enabled in HTTP responses during test sessions. | ||
This is useful for debugging purposes. | ||
""" | ||
monkeypatch.setenv(INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE, "1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we could create a session
scope fixture too with MonkeyPatch
directly: pytest-dev/pytest#1872 (comment)
See here where we do it for a class
fixture:
localstack/tests/aws/scenario/bookstore/test_bookstore.py
Lines 50 to 60 in 4464cd2
@pytest.fixture(scope="class") | |
def patch_opensearch_strategy(self): | |
"""patching the endpoint strategy for opensearch to path, to make the endpoint resolution in the lambda easier""" | |
from _pytest.monkeypatch import MonkeyPatch | |
from localstack import config | |
mpatch = MonkeyPatch() | |
mpatch.setattr(config, "OPENSEARCH_ENDPOINT_STRATEGY", "path") | |
yield mpatch | |
mpatch.undo() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for addressing the comments 🚀
@@ -71,6 +71,8 @@ def pytest_runtestloop(session: Session): | |||
|
|||
# configure | |||
os.environ[ENV_INTERNAL_TEST_RUN] = "1" | |||
localstack_config.INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: do we need this if we have the fixture? I guess it cannot hurt, so I'm fine leaving it like that 👍
Motivation
As a part of the initiative for improving Localstack error messages, this PR aims to conditionally remove stack traces from HTTP responses. A new environment variable
INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE
is introduced, which when enabled, allows stack traces to be included in the HTTP response.This is expected to be always enabled during test runs, where it improves LocalStack developers devX, unless its explicitly disabled. This flag is for internal use only. The stack traces wouldn't appear in the HTTP responses for users unlike before when
DEBUG
is enabled.Current Behaviour:
Expected Behaviour:
Changes
This PR excludes stack traces from HTTP responses when
DEBUG=1
mode is enabled (forDEBUG=0
we already do not log stack trace in the response) and rather allow stack traces whenINCLUDE_STACK_TRACES_IN_HTTP_RESPONSE
is enabled.Related PR in pro https://github.com/localstack/localstack-pro/pull/5003
Testing
The responses to:
INCLUDE_STACK_TRACES_IN_HTTP_RESPONSE
have been tested locally by deliberately introducing an error by assigninga = request["KeyId"][100]
indescribe_key
handler and runawslocal kms describe-key --key-id=411cff4c-e1d0-49cc-9ec7-73ac91049d86
command ensuring expected stack trace behaviour for both cases.TODO