Foundation.Services.TelemetryService (foundation v0.1.4)
GenServer implementation for telemetry collection and metrics.
Provides structured telemetry with automatic metric collection, event emission, and performance monitoring.
Summary
Functions
Returns a specification to start this module under a supervisor.
Emit a histogram metric with default empty metadata.
Emit a histogram metric for distribution analysis.
Reset all metrics (for testing purposes).
Reset all internal state for testing purposes.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Emit a histogram metric with default empty metadata.
Convenience function for emitting histogram metrics when no additional context is needed.
Parameters
event_name
- List of atoms representing the telemetry event pathvalue
- Numeric value to record in the histogram
Examples
iex> emit_histogram([:response, :size], 1024)
:ok
iex> emit_histogram([:processing, :duration], 250.5)
:ok
Returns
:ok
- Metric emitted successfully
Raises
ArgumentError
- If event_name is not a list of atoms or value is not numeric
Emit a histogram metric for distribution analysis.
Histograms track the distribution of values over time and are useful for measuring latencies, sizes, and other continuous metrics.
Parameters
event_name
- List of atoms representing the telemetry event pathvalue
- Numeric value to record in the histogrammetadata
- Map containing additional context for the measurement
Examples
iex> emit_histogram([:api, :request_duration], 150, %{endpoint: "/users"})
:ok
iex> emit_histogram([:database, :query_time], 45.5, %{table: "users"})
:ok
Returns
:ok
- Metric emitted successfully
Raises
ArgumentError
- If event_name is not a list of atoms, value is not numeric, or metadata is not a map
@spec initialize(keyword()) :: :ok | {:error, Foundation.Types.Error.t()}
@spec reset_metrics() :: :ok | {:error, Foundation.Types.Error.t()}
Reset all metrics (for testing purposes).
@spec reset_state() :: :ok | {:error, Foundation.Types.Error.t()}
Reset all internal state for testing purposes.
Clears all metrics, handlers, and resets configuration to defaults. This function should only be used in test environments.
@spec start_link(keyword()) :: GenServer.on_start()
@spec stop() :: :ok