Skip to content

feat(metrics): add flush_metrics() method to allow manual flushing of metrics #2171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,9 @@ If you prefer not to use `log_metrics` because you might want to encapsulate add
???+ warning
Metrics, dimensions and namespace validation still applies

=== "Regular Metrics"

```python hl_lines="10"
--8<-- "examples/metrics/src/flush_metrics.py"
```

=== "Single Metrics"

```python hl_lines="11-14"
--8<-- "examples/metrics/src/single_metric.py"
```
```python hl_lines="12" title="Manually flushing and clearing metrics from memory"
--8<-- "examples/metrics/src/flush_metrics.py"
```

### Metrics isolation

Expand Down
6 changes: 4 additions & 2 deletions examples/metrics/src/flush_metrics.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example file was not being used in the documentation, so I just changed the content and started using it.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@


def lambda_handler(event: dict, context: LambdaContext):
metrics.add_metric(name="SuccessfulBooking", unit=MetricUnit.Count, value=1)
metrics.flush_metrics()
try:
metrics.add_metric(name="SuccessfulBooking", unit=MetricUnit.Count, value=1)
finally:
metrics.flush_metrics()