Raxol.Core.Metrics.Cloud (Raxol v2.6.1)

View Source

Cloud export for the Raxol metrics system.

Buffers metrics and ships them over HTTP to a configured backend:

  • :otlp / :signoz — OTLP/HTTP JSON to an OpenTelemetry collector (POST to the configured endpoint, default /v1/metrics). For :signoz, a configured api_key is sent as signoz-access-token.
  • :datadog — the v1 series API (DD-API-KEY header, requires api_key).
  • :prometheus — Prometheus Pushgateway text exposition (POST; point the endpoint at /metrics/job/<job>).

OTLP and Datadog export every recorded data point (nanosecond timestamps). Prometheus is a snapshot format (repeating a {name, labels} sample is invalid), so it exports the latest value per rendered label set.

Ingestion and flushing

Metrics enter through record/4 (or the equivalent {:metrics, type, name, value, tags} message), which Raxol.Core.Metrics.MetricsCollector.record_metric/4 forwards automatically whenever this process is running. Only numeric values are exported; non-numeric values (the collector also accepts maps) are dropped at ingestion rather than crashing the exporter at flush time.

Automatic exports — the batch-size trigger and the periodic timer — run in a monitored helper process, so a slow or unreachable collector never blocks metric ingestion, and a crash in export code cannot take the exporter down. At most one export is in flight at a time. After a failed export the batch is retained (capped at 10 batches) and the batch-size trigger backs off; the periodic timer is the retry cadence, so an outage costs one attempt per flush_interval, not one per metric.

flush_metrics/0 is the manual/synchronous path (tests, shutdown hooks): it exports in the server and returns the transport result, or {:error, :export_in_flight} if an async export is running.

HTTP transport is Req, an optional dependency; without it every export returns {:error, :http_client_unavailable}.

Crash reports redact api_key (see format_status/1).

CloudWatch is not supported: it needs SigV4 request signing, which means an AWS dependency this library does not take; it is rejected at configuration time rather than silently dropping metrics.

Summary

Functions

Returns a specification to start this module under a supervisor.

Configures the cloud metrics service. The new keys are validated against the configuration that would result (current config merged with the changes), not against defaults.

Flushes buffered metrics to the cloud service now, synchronously in the server. Returns the export result: :ok (also for an empty buffer), {:error, :export_in_flight} when an async export is running, or the transport error.

Gets the current cloud configuration.

Records a metric for cloud export. A no-op returning :ok when the Cloud process is not running or the value is not a number, so producers can call it unconditionally.

Types

cloud_config()

@type cloud_config() :: %{
  service: cloud_service(),
  endpoint: String.t(),
  api_key: String.t() | nil,
  batch_size: pos_integer(),
  flush_interval: pos_integer(),
  compression: boolean()
}

cloud_service()

@type cloud_service() :: :otlp | :signoz | :datadog | :prometheus

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

configure(config)

@spec configure(map()) :: :ok | {:error, term()}

Configures the cloud metrics service. The new keys are validated against the configuration that would result (current config merged with the changes), not against defaults.

flush_metrics()

@spec flush_metrics() :: :ok | {:error, term()}

Flushes buffered metrics to the cloud service now, synchronously in the server. Returns the export result: :ok (also for an empty buffer), {:error, :export_in_flight} when an async export is running, or the transport error.

get_config()

@spec get_config() :: cloud_config()

Gets the current cloud configuration.

handle_manager_cast(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.

record(type, name, value, tags \\ [])

@spec record(atom(), atom() | String.t(), term(), list()) :: :ok

Records a metric for cloud export. A no-op returning :ok when the Cloud process is not running or the value is not a number, so producers can call it unconditionally.

start_link(init_opts \\ [])