-
Notifications
You must be signed in to change notification settings - Fork 58
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
Auto-flush on process exit #141
Conversation
This is an ugly first-pass at auto-flushing before the process exits. This previously required manually flushing, which is easy to forget if everything just happens automatically otherwise. Fixes #136. There's a lot that should be cleaned up here (the `BufferedMetricsLogger` just has way too much logic now, for example). But this gets it working and adds tests. This also adds a `close()` method (maybe it should be renamed? stop? shutdown?) that disables autoflushing and flushes any buffered metrics.
Cleaned this up a bit and it should be good to go. Besides burying too much code in the constructor, I think my initial implementation was a bit too fancy by trying to retain a subtle previous behavior where you could adjust auto-flushing on the fly by changing Since renaming the method to |
Release v0.12.1 with some maintenance updates and the new `process.beforeExit` functionality from #141.
Release v0.12.1 with some maintenance updates and the new `process.beforeExit` functionality from #141.
This is a bit of an ugly first pass. The code needs some cleanup and there are some open questions, but it works and has docs and tests.Fixes #136.This attaches to the process’s
beforeExit
event (supported in Node.js, Deno, and Bun) when auto-flushing is enabled in order to automatically flush when a program exits. Before, you needed to remember to callmetrics.flush()
manually at the end of your program, which is easy to forget (or not even know about in the first place!).It also adds a
close()
method (not sure about the name) that flushes and buffered metrics and disables auto-flushing. It does not prevent adding new metrics to the buffer, but maybe it should? (Would they error? Get dropped silently? Call theonError
handler?)To-do/open questions:
BufferedMetricsLogger
constructor.close()
a good name? Other ideas: (Update: renamed tostop
)stop()
shutdown()
destroy()
disable()
pause()
close()
also prevent buffering new metrics? (i.e. makeaddPoint()
a no-op, or maybe throw an exception or call the global error handler) (Update: decided no for now.)