Go SDK · BufferedRecorder

The default recorder buffers events in memory and flushes in batches. Constructor:

rec := recorder.New(projectID, apiKey, opts...)
// or
rec := es.NewRecorder(opts...)

Options

Option Default Purpose
WithBufferSize(n) 1000 Capacity of the in-memory event buffer.
WithFlushSize(n) 100 Pending-event count that triggers an immediate flush.
WithFlushInterval(d) 5s Max time between flushes when the size threshold isn't reached.
WithFlushTimeout(d) 30s Context timeout per flush call against the inner recorder.
WithOverflowPolicy(p) PolicyDropNewest Behavior when Record finds the buffer full.
WithDrainTimeout(d) 30s Max time Close waits for in-flight events.
WithSlogLogger(l) slog.Default() Logger for diagnostics (overflow warnings, flush errors).
WithBaseURL(url) production Override the ingestion endpoint (tests, staging).
WithHTTPClient(c) Timeout: 10s Custom *http.Client.
WithAutoIdempotencyKey() off Copy Event.ID into IdempotencyKey when the latter is empty.

Overflow policies

recorder.PolicyDropNewest // drop the incoming event, log a warning (default)
recorder.PolicyBlock      // block until space frees or ctx cancels
recorder.PolicyError      // return ErrBufferFull

Close & flush

  • Close() synchronously drains pending events (respects WithDrainTimeout). Call once on shutdown — defer rec.Close() at construction is the idiom.
  • Flush(ctx) drains buffered events at call time. Useful in tests and for graceful shutdown sequences that need to observe drain success.
  • Stats() returns a BufferedStats with Dropped, Flushed, FlushErrs, Pending, BufferSize for observability.