Skip to content
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

MeterProvider to return specific MetricError #2461

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cijothomas
Copy link
Member

Related to #2381
Trying to play with better Error handling, happy to get feedback on the approach..

@cijothomas cijothomas requested a review from a team as a code owner December 20, 2024 05:35
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 54.16667% with 11 lines in your changes missing coverage. Please review.

Project coverage is 76.8%. Comparing base (80629c8) to head (05aac62).

Files with missing lines Patch % Lines
opentelemetry-sdk/src/metrics/error.rs 30.7% 9 Missing ⚠️
opentelemetry-sdk/src/metrics/periodic_reader.rs 77.7% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2461     +/-   ##
=======================================
- Coverage   76.8%   76.8%   -0.1%     
=======================================
  Files        122     122             
  Lines      22217   22231     +14     
=======================================
+ Hits       17082   17086      +4     
- Misses      5135    5145     +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Err(MetricError::Other(
"Cannot perform flush as MeterProvider shutdown already invoked.".into(),
))
Err(MetricError::AlreadyShutdown)
Copy link
Member

Choose a reason for hiding this comment

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

Just to be clear, is this approach different from the one proposed in #2381, where we were using separate enum types for Shutdown, and possibly ForceFlush as well? In this case, the proposal is to use the same MetricError enum for the entire user-facing interface, correct?

Copy link
Contributor

@scottgerring scottgerring Dec 20, 2024

Choose a reason for hiding this comment

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

I believe it is a best practice to have error-per-call when there is a clear disunity of potential errors, like there is between shutdown and export (but probably not between export and forceFlush).

As it stands, shutdown() can return two errors - AlreadyShutdown and ShutdownTimeout (plus the common boxed one for PoisonError).

By adding these types to MetricError we're promising the caller that shutdown() may also return any of Config, ExportErr, InvalidInstrumentConfiguration errors. This is simply not true of the interface, and places extra burden on the caller to handle, leaving the caller with these options:

  • 1/ Treat all errors as unrecoverable - simply match error
  • 2/ Extensively dig through our code, work out that AlreadyShutdown and ShutdownTimeout are two that they care about handling, and _ => to ignore the rest
  • 3/ Exhaustively match all the arms without realising that a bunch of them will never be invoked

Copy link
Member Author

Choose a reason for hiding this comment

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

By adding these types to MetricError we're promising the caller that shutdown() may also return any of Config, ExportErr, InvalidInstrumentConfiguration errors.

Agree this PR is the wrong approach. Thanks for the feedback. Need to rework.

Copy link
Contributor

@scottgerring scottgerring Dec 20, 2024

Choose a reason for hiding this comment

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

Hey @cijothomas I think I overindexed on the single error type - sorry about that. I don't think this needs a dramatic rework!

What you have done with the named-logical-errors makes sense to me! I stole it and lifted it into the other PR for metrics/traces :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants