Skip to content

Comments

feat: add auto-flush for periodic background metric emission#54

Merged
bmorin merged 2 commits intomainfrom
feature/auto-flush
Feb 10, 2026
Merged

feat: add auto-flush for periodic background metric emission#54
bmorin merged 2 commits intomainfrom
feature/auto-flush

Conversation

@MichelMajdalani
Copy link
Collaborator

  • Add Builder::with_auto_flush() with 30s default interval
  • Add Builder::with_auto_flush_interval() for custom intervals
  • Spawn tokio background task with MissedTickBehavior::Skip
  • Add tokio dependency (time, rt features)
  • Refactor Builder::build() to return Collector directly
  • Update documentation and examples

@bmorin
Copy link
Owner

bmorin commented Jan 25, 2026

Thank you for the contribution, nothing stood out as an issue, will look it over again tomorrow and likely merge it.

@peterallwin
Copy link
Contributor

Should this also use spawn_graceful_shutdown_handler to ensure the final metrics are flushed on lambda termination?

@bmorin
Copy link
Owner

bmorin commented Jan 27, 2026

Should this also use spawn_graceful_shutdown_handler to ensure the final metrics are flushed on lambda termination?

Is flushing on the service being Poll::Ready(result) enough? That should flush once per invocation, right?

@peterallwin
Copy link
Contributor

Should this also use spawn_graceful_shutdown_handler to ensure the final metrics are flushed on lambda termination?

Is flushing on the service being Poll::Ready(result) enough? That should flush once per invocation, right?

You're absolutely right, I initially interpreted the feature as replacing the per-invocation flushing with periodic flushing, should have reviewed it completely before commenting.

- Add Builder::with_auto_flush() with 30s default interval
- Add Builder::with_auto_flush_interval() for custom intervals
- Add Builder::with_auto_flush_writer() for custom output destinations
- Add AutoFlushWriterFactory type alias for writer factory pattern
- Spawn tokio background task with MissedTickBehavior::Skip
- Defaults to stdout, but allows testing and non-Lambda use cases
- Add tokio dependency (time, rt features)
- Refactor Builder::build() to return Collector directly
- Update documentation and examples
- Add unit test for custom writer output capture
@bmorin bmorin merged commit 5a37cc6 into main Feb 10, 2026
9 checks passed
@bmorin bmorin deleted the feature/auto-flush branch February 10, 2026 04:12
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