You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the metrics are batched and each call to send only sends up to the metric limit, shutdown may only send one batch of metrics, rather than all metrics in the queue. Furthermore, since the shutdown method is synchronous there's no guarantee that the metrics have actually been flushed by the time it returns.
Suggestion
Change the signature of shutdown to:
interfaceMetric{shutdown: ()=>Promise<void>;}
There are a few things that need to happen for this:
The returned promise should resolve when all the metrics have been sent. This can be achieved by registering an internal sendCallback to know that the metrics have actually been flushed.
shutdown needs to keep calling the send method until there are no more metrics to sent. It may have to do this according to the sendInterval.
All the put methods need to stop accepting new metrics, so as to avoid filling up the queue while trying to drain it. Since the methods are all synchronous and return void, there's no good way to communicate this beyond throwing, but this would be quite a big change for users, so maybe silently dropping metrics added after calling shutdown is a decent compromise? That's essentially what will happen now anyway, so at least it's no worse than the current state.
Concerns
Changing shutdown to start returning a promise means that unless users are aware of this, they may get unhandled promise rejections if something goes wrong. An alternative solution that would make the "block-until-flushed" behavior opt-in would be to have a callback:
Since the metrics are batched and each call to send only sends up to the metric limit,
shutdown
may only send one batch of metrics, rather than all metrics in the queue. Furthermore, since theshutdown
method is synchronous there's no guarantee that the metrics have actually been flushed by the time it returns.Suggestion
Change the signature of
shutdown
to:There are a few things that need to happen for this:
sendCallback
to know that the metrics have actually been flushed.shutdown
needs to keep calling the send method until there are no more metrics to sent. It may have to do this according to thesendInterval
.put
methods need to stop accepting new metrics, so as to avoid filling up the queue while trying to drain it. Since the methods are all synchronous and return void, there's no good way to communicate this beyond throwing, but this would be quite a big change for users, so maybe silently dropping metrics added after callingshutdown
is a decent compromise? That's essentially what will happen now anyway, so at least it's no worse than the current state.Concerns
Changing
shutdown
to start returning a promise means that unless users are aware of this, they may get unhandled promise rejections if something goes wrong. An alternative solution that would make the "block-until-flushed" behavior opt-in would be to have a callback:The text was updated successfully, but these errors were encountered: