ScoutApm.Logging.LogService (scout_apm v2.0.0)

Copy Markdown

Background GenServer that batches and sends log records to an OTLP collector.

Implements a queue with batching and a maximum queue size to prevent memory issues. Follows the same pattern as ScoutApm.Error.ErrorService.

Summary

Functions

Returns a specification to start this module under a supervisor.

Waits for the queue to drain. Used in tests and shutdown.

Checks if logging is enabled.

Forces an immediate flush of queued logs. Used in tests.

Returns the current queue size.

Sends a log record to the service for batched delivery. Non-blocking - returns immediately.

Types

t()

@type t() :: %ScoutApm.Logging.LogService{
  queue: :queue.queue(ScoutApm.Logging.LogRecord.t()),
  queue_size: non_neg_integer(),
  timer_ref: reference() | nil
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

drain(timeout \\ 5000)

@spec drain(timeout :: non_neg_integer()) :: :ok | :timeout

Waits for the queue to drain. Used in tests and shutdown.

enabled?()

@spec enabled?() :: boolean()

Checks if logging is enabled.

flush()

@spec flush() :: :ok

Forces an immediate flush of queued logs. Used in tests.

queue_size()

@spec queue_size() :: non_neg_integer()

Returns the current queue size.

send(record)

@spec send(ScoutApm.Logging.LogRecord.t()) :: :ok

Sends a log record to the service for batched delivery. Non-blocking - returns immediately.

start_link(opts \\ [])