Skip to content

Add batched event delivery with retry, timeout, and queue management#1

Open
jpricardo wants to merge 3 commits intomainfrom
feat/batching
Open

Add batched event delivery with retry, timeout, and queue management#1
jpricardo wants to merge 3 commits intomainfrom
feat/batching

Conversation

@jpricardo
Copy link
Copy Markdown
Owner

Summary

This PR overhauls the JS client's event delivery model from fire-and-forget individual HTTP calls to a buffered, batched pipeline. A matching /logs/batch endpoint is added on the broker server.

Client (logwolf-client/js)

  • capture() is now synchronous — it enqueues the event and returns immediately. The old capture() behavior (respects sampling, sends immediately) is now the behavior of create(), which still awaits server acknowledgement and bypasses the queue.
  • Batched delivery — queued events are flushed on a configurable interval (flushIntervalMs) or eagerly when the batch reaches maxBatchSize.
  • Queue cap — when maxQueueSize is exceeded, the oldest event is dropped and onDropped is called.
  • Retry with backoff — failed batch sends are retried according to retryDelaysMs. Auth errors (401/403) are not retried.
  • Request timeout — all fetch calls now go through fetchWithTimeout() using AbortController, controlled by requestTimeoutMs.
  • LogwolfEvent.stop() — freezes the event's duration at call time. Called automatically by capture() and create(); idempotent.
  • flush() — public method to drain the queue before process exit / page unload.
  • destroy() — stops the background flush interval (useful for clean Node.js shutdown and test teardown).
  • Fixed double serialization: toJson() renamed to toObject(), returning a plain object. JSON.stringify is now done at the send site.
  • New required config fields: flushIntervalMs, maxBatchSize, maxQueueSize, retryDelaysMs, requestTimeoutMs. onDropped is optional.

Server (logwolf-server/broker)

  • New POST /logs/batch endpoint behind the existing API key middleware.
  • Accepts an array of log payloads and emits each as a log.INFO RabbitMQ event, reusing the same emitter pattern as CreateLog.

Breaking changes

  • capture() no longer returns a Promise<void> — it now returns boolean (whether the event was accepted into the queue).
  • LogwolfConfig now requires the new batching fields.
  • LogwolfEvent.toJson() is replaced by toObject().

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
logwolf-docs Ready Ready Preview, Comment Mar 22, 2026 2:59am

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.

1 participant