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
metrics = Metrics(namespace="ServerlessAirline", service="orders") # Sets metric namespace, and service as a metric dimension
66
66
```
67
67
68
-
You can initialize Metrics anywhere in your code - It'll keep track of your aggregate metrics in memory.
69
68
70
69
### Creating metrics
71
70
72
71
You can create metrics using `add_metric`, and you can create dimensions for all your aggregate metrics using `add_dimension` method.
73
72
73
+
!!! tip
74
+
You can initialize Metrics in any other module too. It'll keep track of your aggregate metrics in memory to optimize costs (one blob instead of multiples).
75
+
74
76
=== "Metrics"
75
77
76
78
```python hl_lines="8"
@@ -334,8 +336,7 @@ CloudWatch EMF uses the same dimensions across all your metrics. Use `single_met
334
336
335
337
If you prefer not to use `log_metrics` because you might want to encapsulate additional logic when doing so, you can manually flush and clear metrics as follows:
336
338
337
-
???+ warning
338
-
Metrics, dimensions and namespace validation still applies.
339
+
!!! warning "Warning: Metrics, dimensions and namespace validation still applies"
339
340
340
341
=== "manual_metric_serialization.py"
341
342
@@ -357,9 +358,14 @@ If you prefer not to use `log_metrics` because you might want to encapsulate add
357
358
358
359
### Environment variables
359
360
361
+
!!! tip
362
+
Ignore this section, if you are explicitly setting namespace/default dimension via `namespace` and `service` parameters.
363
+
364
+
For example, `Metrics(namespace=ApplicationName, service=ServiceName)`
365
+
360
366
Use `POWERTOOLS_METRICS_NAMESPACE` and `POWERTOOLS_SERVICE_NAME` env vars when unit testing your code to ensure metric namespace and dimension objects are created, and your code doesn't fail validation.
@@ -378,10 +384,6 @@ If you prefer setting environment variable for specific tests, and are using Pyt
378
384
...
379
385
```
380
386
381
-
#### TODO - below statement is related to Clearing metrics section ?
382
-
383
-
> Ignore this, if you are explicitly setting namespace/default dimension via `namespace` and `service` parameters: `metrics = Metrics(namespace=ApplicationName, service=ServiceName)`
384
-
385
387
### Clearing metrics
386
388
387
389
`Metrics` keep metrics in memory across multiple instances. If you need to test this behaviour, you can use the following Pytest fixture to ensure metrics are reset incl. cold start:
0 commit comments