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
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
+66-55
Original file line number
Diff line number
Diff line change
@@ -160,13 +160,13 @@ To ease routine tasks like extracting correlation ID from popular event sources,
160
160
You can append additional keys using either mechanism:
161
161
162
162
* New keys persist across all future log messages via `append_keys` method
163
-
* New keys persist across all future logs in a specific thread via `append_thread_local_keys` method
164
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.
165
165
166
166
#### append_keys method
167
167
168
168
???+ warning
169
-
`append_keys` is not thread-safe, use `append_thread_local_keys` instead
169
+
`append_keys` is not thread-safe, use [thread_safe_append_keys](#appending-thread-safe-additional-keys) instead
170
170
171
171
You can append your own keys to your existing Logger via `append_keys(**additional_key_values)` method.
172
172
@@ -187,22 +187,6 @@ You can append your own keys to your existing Logger via `append_keys(**addition
187
187
188
188
This example will add `order_id` if its value is not empty, and in subsequent invocations where `order_id` might not be present it'll remove it from the Logger.
189
189
190
-
#### append_thread_local_keys method
191
-
192
-
You can append your own thread-local keys in your existing Logger via the `append_thread_local_keys` method
You can pass an arbitrary number of keyword arguments (kwargs) to all log level's methods, e.g. `logger.info, logger.warning`.
@@ -248,11 +232,10 @@ It accepts any dictionary, and all keyword arguments will be added as part of th
248
232
You can remove additional keys using either mechanism:
249
233
250
234
* Remove new keys across all future log messages via `remove_keys` method
251
-
* Remove new keys across all future logs in a specific thread via `remove_thread_local_keys` method
252
-
* Remove **all** new keys across all future logs in a specific thread via `clear_thread_local_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.
253
236
254
237
???+ danger
255
-
Keys added by `append_keys` can only be removed by `remove_keys` and thread-local keys added by `append_thread_local_key` can only be removed by `remove_thread_local_keys` or `clear_thread_local_keys`. Thread-local and normal logger keys are distinct values and can't be manipulated interchangably.
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.
256
239
257
240
#### remove_keys method
258
241
@@ -270,40 +253,6 @@ You can remove any additional key from Logger state using `remove_keys`.
You can remove any additional thread-local keys from Logger using either `remove_thread_local_keys` or `clear_thread_local_keys`.
276
-
277
-
Use the `remove_thread_local_keys` method to remove a list of thread-local keys that were previously added using the `append_thread_local_keys` method.
Logger is commonly initialized in the global scope. Due to [Lambda Execution Context reuse](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html){target="_blank"}, this means that custom keys can be persisted across invocations. If you want all custom keys to be deleted, you can use `clear_state=True` param in `inject_lambda_context` decorator.
@@ -538,6 +487,68 @@ You can use any of the following built-in JMESPath expressions as part of [injec
538
487
|**APPLICATION_LOAD_BALANCER**|`'headers."x-amzn-trace-id"'`| ALB X-Ray Trace ID |
539
488
|**EVENT_BRIDGE**|`"id"`| EventBridge Event ID |
540
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