File tree Expand file tree Collapse file tree 4 files changed +33
-2
lines changed
aws_lambda_powertools/logging Expand file tree Collapse file tree 4 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66
77## [ Unreleased]
88
9+ ## [ 1.0.1] - 2020-07-06
10+ ### Fixed
11+ - ** Logger** : Fix a bug with ` inject_lambda_context ` causing existing an Logger keys to be overriden if ` structure_logs ` was called before
12+
913## [ 1.0.0] - 2020-06-18
1014### Added
1115- ** Metrics** : ` add_metadata ` method to add any metric metadata you'd like to ease finding metric related data via CloudWatch Logs
Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ def decorate(event, context):
197197 lambda_context = build_lambda_context_model (context )
198198 cold_start = _is_cold_start ()
199199
200- self .structure_logs (cold_start = cold_start , ** lambda_context .__dict__ )
200+ self .structure_logs (append = True , cold_start = cold_start , ** lambda_context .__dict__ )
201201 return lambda_handler (event , context )
202202
203203 return decorate
Original file line number Diff line number Diff line change 11[tool .poetry ]
22name = " aws_lambda_powertools"
3- version = " 1.0.0 "
3+ version = " 1.0.1 "
44description = " Python utilities for AWS Lambda functions including but not limited to tracing, logging and custom metric"
55authors = [" Amazon Web Services" ]
66classifiers =[
Original file line number Diff line number Diff line change @@ -256,3 +256,30 @@ def test_logger_invalid_sampling_rate():
256256 # THEN we should raise InvalidLoggerSamplingRateError
257257 with pytest .raises (InvalidLoggerSamplingRateError ):
258258 Logger (sampling_rate = "TEST" )
259+
260+
261+ def test_inject_lambda_context_with_structured_log (lambda_context , stdout ):
262+ # GIVEN Logger is initialized
263+ logger = Logger (stream = stdout )
264+
265+ # WHEN structure_logs has been used to add an additional key upfront
266+ # and a lambda function is decorated with logger.inject_lambda_context
267+ logger .structure_logs (append = True , additional_key = "test" )
268+
269+ @logger .inject_lambda_context
270+ def handler (event , context ):
271+ logger .info ("Hello" )
272+
273+ handler ({}, lambda_context )
274+
275+ # THEN lambda contextual info should always be in the logs
276+ log = capture_logging_output (stdout )
277+ expected_logger_context_keys = (
278+ "function_name" ,
279+ "function_memory_size" ,
280+ "function_arn" ,
281+ "function_request_id" ,
282+ "additional_key" ,
283+ )
284+ for key in expected_logger_context_keys :
285+ assert key in log
You can’t perform that action at this time.
0 commit comments