-
Notifications
You must be signed in to change notification settings - Fork 821
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
Metric Observer - change from callback to Observable #954
Comments
Are you thinking to implement Observable or import some Observable library? |
I would implement the basic Observable, no need for 3rd party lib |
and then the code for
|
in fact we could have both callback if someone needs just a sync operation (as it is now) or observer for any async operations |
@mayurkale22 && @open-telemetry/javascript-approvers would like to hear your thoughts on that, thx |
Looks fine to me 👍 |
Can we do this and still remain compliant to the spec? I want to stay as similar to other sigs as possible |
the spec says it should be callback - for sync operation we can have like this, but for async I don't see so far any easy way to be able to do it. So we can easily support 2 cases. The biggest advantage will be that we can support async operation without trying to fix the problem of waiting for async to finish and the time of lastUpdate will be correct too. Besides that the change won't be so big too |
I think it's a good idea let's go for it |
@obecny were you thinking you wanted to take this? |
So this will change only internals of the implementations and not on API side, (No breaking change) right? |
@dyladan yes as I'm working on metrics now anyway, so that's the whole idea where it comes from |
@mayurkale22 we will have to extend our metrics to allow for callback and for Observable |
@mayurkale22 here ->
|
@mayurkale22 it is backwards compatible change for metrics as it should just add one additional type accepted by the Currently we have function getCpuUsage() {
return Math.random();
}
otelCpuUsage.setCallback((observerResult) => {
observerResult.observe(getCpuUsage, { pid: process.pid });
}); We wil extend it to allow: function getDiskUsage() {
return Math.random();
}
const diskObservable = new MetricObservable();
// update disk usage every 10 seconds
setInterval(() => diskObservable.next(getDiskUsage()), 10_000)
otelDiskUsage.setCallback((observerResult) => {
observerResult.observe(diskObservable, { disk: 0 });
}); |
@dyladan correct |
But the whole idea is to allow for something like this const diskObservable = new MetricObservable();
function getDiskUsage() {
someAsyncPromiseEtc().then((value)=>{
diskObservable.next(value);
})
}
// update disk usage every 10 seconds
setInterval(getDiskUsage, 10_000)
otelDiskUsage.setCallback((observerResult) => {
observerResult.observe(diskObservable, { disk: 0 });
}); |
Right, I just thought the sync example was easier to read for the example. We're on the same page :) |
|
Currently Metric Observer is using callback to get a value. The callback is called periodically, and is returning the value. This is causing the problem to be able to update value in asynchronous operation. If we change the callback to Observable we will be able to set the value at any given time. It would look then more less like this
WDYT ?
The text was updated successfully, but these errors were encountered: