You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Getting baseline thread safe keys working
* Functional tests for thread safe keys
* Updating documentation
* Cleanup
* Small fixes for linting
* Clearing thread local keys with clear_state=True
* Cleaning up PR
* Small fixes to docs
* Fixing type annotations for THREAD_LOCAL_KEYS
* Replacing '|' with {**dict1, **dict2} due to support of Python < 3.9
* fix types from v2 to v3
* Changing documentation and method names
---------
Co-authored-by: Simon Thulbourn <[email protected]>
Co-authored-by: Leandro Damascena <[email protected]>
Copy file name to clipboardExpand all lines: docs/core/event_handler/api_gateway.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -128,11 +128,12 @@ Here's an example on how we can handle the `/todos` path.
128
128
129
129
When using Amazon API Gateway HTTP API to front your Lambda functions, you can use `APIGatewayHttpResolver`.
130
130
131
+
<!-- markdownlint-disable MD013 -->
131
132
???+ note
132
133
Using HTTP API v1 payload? Use `APIGatewayRestResolver` instead. `APIGatewayHttpResolver` defaults to v2 payload.
133
134
134
-
<!-- markdownlint-disable-next-line MD013 -->
135
135
If you're using Terraform to deploy a HTTP API, note that it defaults the [payload_format_version](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/apigatewayv2_integration#payload_format_version){target="_blank" rel="nofollow"} value to 1.0 if not specified.
136
+
<!-- markdownlint-enable MD013 -->
136
137
137
138
```python hl_lines="5 11" title="Using HTTP API resolver"
Copy file name to clipboardExpand all lines: docs/core/logger.md
+78-2
Original file line number
Diff line number
Diff line change
@@ -159,13 +159,14 @@ To ease routine tasks like extracting correlation ID from popular event sources,
159
159
160
160
You can append additional keys using either mechanism:
161
161
162
-
*Persist new keys across all future log messages via `append_keys` method
162
+
*New keys persist across all future log messages via `append_keys` method
163
163
* Add additional keys on a per log message basis as a keyword=value, or via `extra` parameter
164
+
* New keys persist across all future logs in a specific thread via `thread_safe_append_keys` method. Check [Working with thread-safe keys](#working-with-thread-safe-keys) section.
164
165
165
166
#### append_keys method
166
167
167
168
???+ warning
168
-
`append_keys` is not thread-safe, please see [RFC](https://github.com/aws-powertools/powertools-lambda-python/issues/991){target="_blank"}.
169
+
`append_keys` is not thread-safe, use [thread_safe_append_keys](#appending-thread-safe-additional-keys) instead
169
170
170
171
You can append your own keys to your existing Logger via `append_keys(**additional_key_values)` method.
171
172
@@ -228,6 +229,16 @@ It accepts any dictionary, and all keyword arguments will be added as part of th
228
229
229
230
### Removing additional keys
230
231
232
+
You can remove additional keys using either mechanism:
233
+
234
+
* Remove new keys across all future log messages via `remove_keys` method
235
+
* Remove keys persist across all future logs in a specific thread via `thread_safe_remove_keys` method. Check [Working with thread-safe keys](#working-with-thread-safe-keys) section.
236
+
237
+
???+ danger
238
+
Keys added by `append_keys` can only be removed by `remove_keys` and thread-local keys added by `thread_safe_append_keys` can only be removed by `thread_safe_remove_keys` or `thread_safe_clear_keys`. Thread-local and normal logger keys are distinct values and can't be manipulated interchangeably.
239
+
240
+
#### remove_keys method
241
+
231
242
You can remove any additional key from Logger state using `remove_keys`.
232
243
233
244
=== "remove_keys.py"
@@ -284,6 +295,9 @@ You can view all currently configured keys from the Logger state using the `get_
284
295
--8<-- "examples/logger/src/get_current_keys.py"
285
296
```
286
297
298
+
???+ info
299
+
For thread-local additional logging keys, use `get_current_thread_keys` instead
300
+
287
301
### Log levels
288
302
289
303
The default log level is `INFO`. It can be set using the `level` constructor option, `setLevel()` method or by using the `POWERTOOLS_LOG_LEVEL` environment variable.
@@ -473,6 +487,68 @@ You can use any of the following built-in JMESPath expressions as part of [injec
473
487
|**APPLICATION_LOAD_BALANCER**|`'headers."x-amzn-trace-id"'`| ALB X-Ray Trace ID |
474
488
|**EVENT_BRIDGE**|`"id"`| EventBridge Event ID |
475
489
490
+
### Working with thread-safe keys
491
+
492
+
#### Appending thread-safe additional keys
493
+
494
+
You can append your own thread-local keys in your existing Logger via the `thread_safe_append_keys` method
You can view all currently thread-local keys from the Logger state using the `thread_safe_get_current_keys()` method. This method is useful when you need to avoid overwriting keys that are already configured.
Similar to [Tracer](./tracer.md#reusing-tracer-across-your-code){target="_blank"}, a new instance that uses the same `service` name will reuse a previous Logger instance.
0 commit comments