Skip to content

Commit 8daf20c

Browse files
committed
docs: add metrics metadata #80
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
1 parent 0fed904 commit 8daf20c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/content/core/metrics.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,56 @@ with single_metric(name="ColdStart", unit=MetricUnit.Count, value=1, namespace="
8989
...
9090
```
9191

92+
## Adding metadata
93+
94+
You can use `add_metadata` for advanced use cases, where you want to metadata as part of the serialized metrics object.
95+
96+
<Note type="info">
97+
<strong>This will not be available during metrics visualization</strong> - Use <strong>dimensions</strong> for this purpose
98+
</Note><br/>
99+
100+
```python:title=app.py
101+
from aws_lambda_powertools import Metrics
102+
from aws_lambda_powertools.metrics import MetricUnit
103+
104+
metrics = Metrics(namespace="ExampleApplication", service="booking")
105+
metrics.add_metric(name="SuccessfulBooking", unit=MetricUnit.Count, value=1)
106+
metrics.add_metadata(key="booking_id", value="booking_uuid") # highlight-line
107+
```
108+
109+
This will be available in CloudWatch Logs to ease operations on high cardinal data.
110+
111+
<details>
112+
<summary><strong>Exerpt output in CloudWatch Logs</strong></summary>
113+
114+
```json:title=cloudwatch_logs.json
115+
{
116+
"SuccessfulBooking": 1.0,
117+
"_aws": {
118+
"Timestamp": 1592234975665,
119+
"CloudWatchMetrics": [
120+
{
121+
"Namespace": "ExampleApplication",
122+
"Dimensions": [
123+
[
124+
"service"
125+
]
126+
],
127+
"Metrics": [
128+
{
129+
"Name": "SuccessfulBooking",
130+
"Unit": "Count"
131+
}
132+
]
133+
}
134+
]
135+
},
136+
"service": "booking",
137+
"booking_id": "booking_uuid" // highlight-line
138+
}
139+
```
140+
</details>
141+
92142
## Flushing metrics
93143

94144
As you finish adding all your metrics, you need to serialize and flush them to standard output. You can do that right before you return your response to the caller via `log_metrics`.

0 commit comments

Comments
 (0)