Skip to content

Commit 6d5f148

Browse files
committed
Removed env variable and default stack trace logging to True
1 parent fee5479 commit 6d5f148

File tree

6 files changed

+14
-34
lines changed

6 files changed

+14
-34
lines changed

aws_lambda_powertools/logging/formatter.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(
8282
log_record_order: List[str] | None = None,
8383
utc: bool = False,
8484
use_rfc3339: bool = False,
85-
serialize_stacktrace: bool = None,
85+
serialize_stacktrace: bool = True,
8686
**kwargs,
8787
) -> None:
8888
"""Return a LambdaPowertoolsFormatter instance.
@@ -154,9 +154,7 @@ def __init__(
154154
self.keys_combined = {**self._build_default_keys(), **kwargs}
155155
self.log_format.update(**self.keys_combined)
156156

157-
self.serialize_stacktrace = resolve_truthy_env_var_choice(env=os.getenv(constants.POWERTOOLS_STACKTRACE_ENV, "false"),
158-
choice=serialize_stacktrace,
159-
)
157+
self.serialize_stacktrace = serialize_stacktrace
160158

161159
super().__init__(datefmt=self.datefmt)
162160

aws_lambda_powertools/logging/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def __init__(
220220
log_record_order: Optional[List[str]] = None,
221221
utc: bool = False,
222222
use_rfc3339: bool = False,
223-
serialize_stacktrace: bool = None,
223+
serialize_stacktrace: bool = True,
224224
**kwargs,
225225
) -> None:
226226
self.service = resolve_env_var_choice(

aws_lambda_powertools/shared/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,3 @@
4242

4343
POWERTOOLS_DEV_ENV: str = "POWERTOOLS_DEV"
4444
POWERTOOLS_DEBUG_ENV: str = "POWERTOOLS_DEBUG"
45-
46-
POWERTOOLS_STACKTRACE_ENV: str = "POWERTOOLS_LOGGER_SERIALIZE_STACKTRACE"

docs/core/logger.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ Logger can optionally log uncaught exceptions by setting `log_uncaught_exception
321321

322322
#### Stack trace logging
323323

324-
Logger can optionally log the full stack trace as JSON by setting `logger_formatter=LambdaPowertoolsFormatter(serialize_stacktrace=True)` at initialization. Optionally, setting the `POWERTOOLS_LOGGER_SERIALIZE_STACKTRACE` environment variable to `true` will include stacktrace information in the logs.
324+
Logger can optionally log the full stack trace as JSON by setting `logger_formatter=LambdaPowertoolsFormatter(serialize_stacktrace=True)` at initialization.
325325

326326
=== "logging_stacktrace.py"
327327

@@ -368,7 +368,6 @@ The following environment variables are available to configure Logger at a globa
368368
| **Event Logging** | Whether to log the incoming event. | `POWERTOOLS_LOGGER_LOG_EVENT` | `false` |
369369
| **Debug Sample Rate** | Sets the debug log sampling. | `POWERTOOLS_LOGGER_SAMPLE_RATE` | `0` |
370370
| **Disable Deduplication** | Disables log deduplication filter protection to use Pytest Live Log feature. | `POWERTOOLS_LOG_DEDUPLICATION_DISABLED` | `false` |
371-
| **Include Stack Trace** | Includes JSON formatted stack trace in the log output. | `POWERTOOLS_LOGGER_SERIALIZE_STACKTRACE` | `false` |
372371

373372
[`POWERTOOLS_LOGGER_LOG_EVENT`](#logging-incoming-event) can also be set on a per-method basis, and [`POWERTOOLS_LOGGER_SAMPLE_RATE`](#sampling-debug-logs) on a per-instance basis. These parameter values will override the environment variable value.
374373

docs/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,6 @@ Core utilities such as Tracing, Logging, Metrics, and Event Handler will be avai
723723
| **POWERTOOLS_PARAMETERS_SSM_DECRYPT** | Sets whether to decrypt or not values retrieved from AWS SSM Parameters Store | [Parameters](./utilities/parameters.md#ssmprovider){target="_blank"} | `false` |
724724
| **POWERTOOLS_DEV** | Increases verbosity across utilities | Multiple; see [POWERTOOLS_DEV effect below](#optimizing-for-non-production-environments) | `false` |
725725
| **LOG_LEVEL** | Sets logging level | [Logging](./core/logger.md){target="_blank"} | `INFO` |
726-
| **POWERTOOLS_LOGGER_SERIALIZE_STACKTRACE** | Include JSON formatted stack trace in log message | [Logging](./core/logger.md){target="_blank"} | `false` |
727726

728727
### Optimizing for non-production environments
729728

tests/functional/test_logger.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ def test_stream_defaults_to_stdout(service_name, capsys):
960960
log = json.loads(capsys.readouterr().out.strip())
961961
assert log["message"] == msg
962962

963-
def test_logger_logs_no_stack_trace_without_parameter(stdout):
963+
def test_logger_logs_stack_trace_without_parameter(stdout):
964964
logger = Logger(stream=stdout)
965965

966966
try:
@@ -969,7 +969,7 @@ def test_logger_logs_no_stack_trace_without_parameter(stdout):
969969
logger.exception(e)
970970

971971
log = capture_logging_output(stdout)
972-
assert "stack_trace" not in log
972+
assert "stack_trace" in log
973973

974974
def test_logger_logs_stack_trace_with_parameter(stdout):
975975
logger = Logger(stream=stdout, logger_formatter=LambdaPowertoolsFormatter(serialize_stacktrace=True))
@@ -982,21 +982,8 @@ def test_logger_logs_stack_trace_with_parameter(stdout):
982982
log = capture_logging_output(stdout)
983983
assert "stack_trace" in log
984984

985-
def test_logger_logs_stack_trace_with_env_var(stdout, monkeypatch: pytest.MonkeyPatch):
986-
monkeypatch.setenv(constants.POWERTOOLS_STACKTRACE_ENV, "true")
987-
logger = Logger(stream=stdout)
988-
989-
try:
990-
raise ValueError("Something went wrong")
991-
except Exception as e:
992-
logger.exception(e)
993-
994-
log = capture_logging_output(stdout)
995-
assert "stack_trace" in log
996-
997-
def test_logger_logs_no_stack_trace_with_env_var(stdout, monkeypatch: pytest.MonkeyPatch):
998-
monkeypatch.setenv(constants.POWERTOOLS_STACKTRACE_ENV, "false")
999-
logger = Logger(stream=stdout)
985+
def test_logger_logs_no_stack_trace_with_parameter_false(stdout):
986+
logger = Logger(stream=stdout, logger_formatter=LambdaPowertoolsFormatter(serialize_stacktrace=False))
1000987

1001988
try:
1002989
raise ValueError("Something went wrong")
@@ -1006,25 +993,24 @@ def test_logger_logs_no_stack_trace_with_env_var(stdout, monkeypatch: pytest.Mon
1006993
log = capture_logging_output(stdout)
1007994
assert "stack_trace" not in log
1008995

1009-
def test_logger_logs_no_stack_trace_with_parameter_override(stdout, monkeypatch: pytest.MonkeyPatch):
1010-
monkeypatch.setenv(constants.POWERTOOLS_STACKTRACE_ENV, "true")
1011-
logger = Logger(stream=stdout, logger_formatter=LambdaPowertoolsFormatter(serialize_stacktrace=False))
996+
def test_logger_logs_stack_trace_with_logger_parameter(stdout):
997+
logger = Logger(stream=stdout, serialize_stacktrace=True)
1012998

1013999
try:
10141000
raise ValueError("Something went wrong")
10151001
except Exception as e:
10161002
logger.exception(e)
10171003

10181004
log = capture_logging_output(stdout)
1019-
assert "stack_trace" not in log
1005+
assert "stack_trace" in log.keys()
10201006

1021-
def test_logger_logs_stack_trace_with_logger_parameter(stdout):
1022-
logger = Logger(stream=stdout, serialize_stacktrace=True)
1007+
def test_logger_logs_no_stack_trace_with_logger_parameter_false(stdout):
1008+
logger = Logger(stream=stdout, serialize_stacktrace=False)
10231009

10241010
try:
10251011
raise ValueError("Something went wrong")
10261012
except Exception as e:
10271013
logger.exception(e)
10281014

10291015
log = capture_logging_output(stdout)
1030-
assert "stack_trace" in log.keys()
1016+
assert "stack_trace" not in log.keys()

0 commit comments

Comments
 (0)