File tree 4 files changed +33
-2
lines changed
aws_lambda_powertools/logging
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
6
6
7
7
## [ Unreleased]
8
8
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
+
9
13
## [ 1.0.0] - 2020-06-18
10
14
### Added
11
15
- ** 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):
197
197
lambda_context = build_lambda_context_model (context )
198
198
cold_start = _is_cold_start ()
199
199
200
- self .structure_logs (cold_start = cold_start , ** lambda_context .__dict__ )
200
+ self .structure_logs (append = True , cold_start = cold_start , ** lambda_context .__dict__ )
201
201
return lambda_handler (event , context )
202
202
203
203
return decorate
Original file line number Diff line number Diff line change 1
1
[tool .poetry ]
2
2
name = " aws_lambda_powertools"
3
- version = " 1.0.0 "
3
+ version = " 1.0.1 "
4
4
description = " Python utilities for AWS Lambda functions including but not limited to tracing, logging and custom metric"
5
5
authors = [" Amazon Web Services" ]
6
6
classifiers =[
Original file line number Diff line number Diff line change @@ -256,3 +256,30 @@ def test_logger_invalid_sampling_rate():
256
256
# THEN we should raise InvalidLoggerSamplingRateError
257
257
with pytest .raises (InvalidLoggerSamplingRateError ):
258
258
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