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

Link to this function

add(server, item)

View Source (since 12.0.0)
@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.

Link to this function

category(server)

View Source (since 12.0.0)

Returns the buffer's category.

Link to this function

child_spec(init_arg)

View Source (since 12.0.0)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

drain(server)

View Source (since 12.0.0)
@spec drain(GenServer.server()) :: [term()]

Drains all items from the buffer.

Returns a list of all items in FIFO order.

Link to this function

is_ready?(server)

View Source (since 12.0.0)
@spec is_ready?(GenServer.server()) :: boolean()

Returns whether the buffer is ready to flush.

Link to this function

poll_if_ready(server)

View Source (since 12.0.0)
@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.

Link to this function

size(server)

View Source (since 12.0.0)
@spec size(GenServer.server()) :: non_neg_integer()

Returns the current number of items in the buffer.

Link to this function

start_link(opts)

View Source (since 12.0.0)
@spec start_link(keyword()) :: GenServer.on_start()

Starts the buffer process.