-
Notifications
You must be signed in to change notification settings - Fork 685
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
Add SumObserver and UpDownSumObserver instruments #789
Conversation
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.
LGTM!
opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/batcher.py
Outdated
Show resolved
Hide resolved
@@ -189,6 +189,30 @@ def observe(self, value: ValueT, labels: Dict[str, str]) -> None: | |||
""" | |||
|
|||
|
|||
class SumObserver(Observer): |
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 think you need to update the ObserverT
TypeVar in this file
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.
Currently we have ObserverT = TypeVar("ObserverT", bound=Observer)
. I believe as long as the class used is a subclass of "Observer" this definition should be accurate?
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.
Oh sorry you're right!
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.
Overall a couple minor changes, but I think the code does as expected.
Unrelated to this PR per se, but: I feel like both of these observers Sum and UpDownSum, aren't super valuable.
At the end of the day, all these things do is provide a sanity check for a developer who uses them, by providing guarantees around the value itself.
Theres edge cases here especially with things like monotonic counters that will be nasty, including:
- random resets back to 0 that occur due to some internal counter in the kernel resetting, or some value outside of this. SumObserver is still the right category of observer here, but you'll be violating it's constraint through no fall of your own.
In my experience these type of constraints can be handled on the consumer side, with functions or operations like nonNegativeDerivative which will show you the rate by which something is increasing.
@toumorokoshi |
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.
LGTM, some non-blocking suggestions
Co-authored-by: alrex <[email protected]>
Co-authored-by: alrex <[email protected]>
Resolves [#755] and [#756]
Abstracts
Observer
instrument as a base class for all asynchronous instruments.SumObserver and UpDownSumObserver are also cumulative, so they use the LastValueAggregator to record.
Observed values must also be non-decreasing, compared to the previous observed value for SumObserver. Observed values can be any value for UpDownSumObserver .