View Source Sentry.Telemetry.Scheduler (Sentry v12.0.3)

GenServer implementing a weighted round-robin scheduler for telemetry buffers.

The scheduler cycles through category buffers based on priority weights, ensuring critical telemetry gets priority over high-volume data under load.

Weights

  • :critical - weight 5 (errors)
  • :high - weight 4 (check-ins)
  • :medium - weight 3 (transactions)
  • :low - weight 2 (logs)

Signal-Based Wake

The scheduler sleeps until signaled via signal/1. When signaled, it wakes and attempts to process items from the current buffer in the cycle. If the buffer is not ready or the transport queue is full, it advances to the next position.

Transport Queue

The scheduler includes a bounded FIFO queue for transport concurrency control, processing one envelope at a time (single-worker model). The queue is capped at a configurable capacity (default 1000 items) to prevent unbounded memory growth. For log envelopes, each log event counts as one item toward capacity.

Summary

Functions

Builds a priority cycle based on category weights.

Returns a specification to start this module under a supervisor.

Flushes all buffers by draining their contents and sending all items.

Signals the scheduler to wake and process items.

Starts the scheduler process.

Types

Link to this type

buffers()

View Source (since 12.0.0)
@type buffers() :: %{
  error: GenServer.server(),
  check_in: GenServer.server(),
  transaction: GenServer.server(),
  log: GenServer.server()
}
@type t() :: %Sentry.Telemetry.Scheduler{
  active_item_count: non_neg_integer(),
  active_ref: reference() | nil,
  buffers: buffers(),
  capacity: pos_integer(),
  cycle_position: non_neg_integer(),
  on_envelope: (Sentry.Envelope.t() -> any()) | nil,
  priority_cycle: [Sentry.Telemetry.Category.t()],
  queue: :queue.queue(),
  size: non_neg_integer()
}

Functions

Link to this function

build_priority_cycle(weights \\ nil)

View Source (since 12.0.0)
@spec build_priority_cycle(map() | nil) :: [Sentry.Telemetry.Category.t()]

Builds a priority cycle based on category weights.

Returns a list of categories where each category appears a number of times equal to its priority weight.

Examples

iex> Sentry.Telemetry.Scheduler.build_priority_cycle()
[:error, :error, :error, :error, :error, :check_in, :check_in, :check_in, :check_in, :transaction, :transaction, :transaction, :log, :log]
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

flush(server, timeout \\ 5000)

View Source (since 12.0.0)
@spec flush(GenServer.server(), timeout()) :: :ok

Flushes all buffers by draining their contents and sending all items.

This is a blocking call that returns when all items have been processed, including any envelopes queued for transport.

Link to this function

signal(server)

View Source (since 12.0.0)
@spec signal(GenServer.server()) :: :ok

Signals the scheduler to wake and process items.

This is a non-blocking call that triggers the scheduler to check buffers and send any ready items.

Link to this function

start_link(opts)

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

Starts the scheduler process.

Options

  • :buffers - Map of category to buffer pid (required)
  • :name - The name to register the GenServer under (optional)
  • :weights - Custom priority weights (optional)
  • :on_envelope - Callback function invoked with built envelopes (optional)
  • :capacity - Maximum items in the transport queue (default: 1000)