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
@@ -143,6 +143,89 @@ When debugging in non-production environments, you can instruct Logger to log th
143
143
...
144
144
```
145
145
146
+
#### Setting a Correlation ID
147
+
148
+
> New in 1.12.0
149
+
150
+
You can set a Correlation ID using `correlation_id_path` param by passing a [JMESPath expression](https://jmespath.org/tutorial.html){target="_blank"}.
We provide [built-in JMESPath expressions](#built-in-correlation-id-expressions) for known event sources, where either a request ID or X-Ray Trace ID are present.
190
+
191
+
=== "collect.py"
192
+
193
+
```python hl_lines="2"
194
+
from aws_lambda_powertools import Logger
195
+
from aws_lambda_powertools.logging import correlation_paths
You can append additional keys using either mechanism:
@@ -188,24 +271,58 @@ You can append your own keys to your existing Logger via `structure_logs(append=
188
271
189
272
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.
190
273
191
-
#### Setting correlation ID
274
+
#### extra parameter
192
275
193
-
You can set a correlation_id to your existing Logger via `set_correlation_id(value)` method.
276
+
> New in 1.10.0
277
+
278
+
Extra parameter is available for all log levels' methods, as implemented in the standard logging library - e.g. `logger.info, logger.warning`.
279
+
280
+
It accepts any dictionary, and all keyword arguments will be added as part of the root structure of the logs for that log statement.
281
+
282
+
!!! info "Any keyword argument added using `extra` will not be persisted for subsequent messages."
283
+
284
+
=== "extra_parameter.py"
285
+
286
+
```python hl_lines="6"
287
+
logger = Logger(service="payment")
288
+
289
+
fields = { "request_id": "1123" }
290
+
291
+
logger.info("Hello", extra=fields)
292
+
```
293
+
=== "Example CloudWatch Logs excerpt"
294
+
295
+
```json hl_lines="7"
296
+
{
297
+
"timestamp": "2021-01-12 14:08:12,357",
298
+
"level": "INFO",
299
+
"location": "collect.handler:1",
300
+
"service": "payment",
301
+
"sampling_rate": 0.0,
302
+
"request_id": "1123",
303
+
"message": "Collecting payment"
304
+
}
305
+
```
306
+
307
+
#### set_correlation_id method
308
+
309
+
> New in 1.12.0
310
+
311
+
You can set a correlation_id to your existing Logger via `set_correlation_id(value)` method by passing any string value.
194
312
195
313
=== "collect.py"
196
314
197
-
```python hl_lines="8"
315
+
```python hl_lines="6"
198
316
from aws_lambda_powertools import Logger
199
-
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
0 commit comments