View Source Sentry.Telemetry.Buffer (Sentry v12.0.3)
A fixed-capacity FIFO buffer for telemetry items with batch-aware flushing.
This module is both a GenServer and a struct. The struct holds the buffer state (a bounded queue with overflow-drops-oldest semantics), while the GenServer provides concurrent access for producers and consumers.
Options
:category- The telemetry category (required), currently only:log:name- The name to register the GenServer under (optional):capacity- Buffer capacity (defaults to category default):batch_size- Items per batch (defaults to category default):timeout- Flush timeout in ms (defaults to category default):on_item- Optional callback function invoked when an item is added
Summary
Functions
Adds an item to the buffer.
Returns the buffer's category.
Returns a specification to start this module under a supervisor.
Drains all items from the buffer.
Returns whether the buffer is ready to flush.
Polls a batch of items if the buffer is ready to flush.
Returns the current number of items in the buffer.
Starts the buffer process.
Types
@type t() :: %Sentry.Telemetry.Buffer{ batch_size: pos_integer(), capacity: pos_integer(), category: Sentry.Telemetry.Category.t(), items: :queue.queue(), last_flush_time: integer(), on_item: (() -> any()) | nil, size: non_neg_integer(), timeout: pos_integer() | nil }
Functions
@spec add(GenServer.server(), term()) :: :ok
Adds an item to the buffer.
Returns :ok. If the buffer is full, the oldest item is dropped.
If an on_item callback was provided, it will be invoked.
@spec category(GenServer.server()) :: Sentry.Telemetry.Category.t()
Returns the buffer's category.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec drain(GenServer.server()) :: [term()]
Drains all items from the buffer.
Returns a list of all items in FIFO order.
@spec is_ready?(GenServer.server()) :: boolean()
Returns whether the buffer is ready to flush.
@spec poll_if_ready(GenServer.server()) :: {:ok, [term()]} | :not_ready
Polls a batch of items if the buffer is ready to flush.
Returns {:ok, items} if ready, or :not_ready if not.
@spec size(GenServer.server()) :: non_neg_integer()
Returns the current number of items in the buffer.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the buffer process.