-
Notifications
You must be signed in to change notification settings - Fork 910
Propagate flush to PeriodicMetricReader's metricExporter. #7410
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
Conversation
On a synchronous exporter this doesn't matter, but the API design allows for asynchronous exporters, which requires calling flush after manually exporting. Fixes open-telemetry#7343
| CompletableResultCode result = new CompletableResultCode(); | ||
| CompletableResultCode flushResult = scheduled.doRun(); | ||
| flushResult.whenComplete( | ||
| () -> | ||
| exporter | ||
| .flush() | ||
| .whenComplete( | ||
| () -> { | ||
| if (!flushResult.isSuccess()) { | ||
| result.fail(); | ||
| } else { | ||
| result.succeed(); | ||
| } | ||
| })); | ||
| return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this pattern in enough places I wonder if it would be worth adding CompletableResultCode.whenComplete(Callable<CompletableResultCode>) that handles this logic in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7410 +/- ##
=========================================
Coverage 89.75% 89.76%
- Complexity 6981 6985 +4
=========================================
Files 797 797
Lines 21165 21175 +10
Branches 2057 2057
=========================================
+ Hits 18997 19007 +10
+ Misses 1505 1504 -1
- Partials 663 664 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Also, this behavior is indeed explicitly called out in the spec: https://github.com/open-telemetry/opentelemetry-specification/blame/18a37a1ed8dff267e72824fa066d9d46dbaede7e/specification/metrics/sdk.md#L1436-L1443
On a synchronous exporter this doesn't matter, but the API design allows for asynchronous exporters, which requires calling flush after manually exporting.
Fixes #7343