Forge.Telemetry.Metrics (Forge v0.1.1)
View SourceTelemetry metrics definitions for Forge pipelines.
This module defines metric specifications that can be consumed by various telemetry reporters (StatsD, Prometheus, etc.) using the TelemetryMetrics library pattern.
Metric Categories
Counters
- Pipeline completions (by outcome)
- Stage executions (by stage, outcome)
- Retry attempts (by stage)
- DLQ enqueues (by stage, error)
- Measurement cache hits/misses
Distributions (Histograms)
- Pipeline duration
- Stage latency (by stage)
- Measurement computation time
- Storage operation latency
- Artifact upload/download sizes
Usage with Reporters
This module provides metric definitions that can be used with different telemetry reporters. Since telemetry_metrics is an optional dependency, these are provided as plain maps that reporters can adapt.
Example: Custom Reporter
defmodule MyApp.TelemetryReporter do
def attach do
metrics = Forge.Telemetry.Metrics.metrics()
Enum.each(metrics, fn metric ->
:telemetry.attach(
"my-reporter-#{metric.name}",
metric.event_name,
&handle_event/4,
metric
)
end)
end
defp handle_event(event, measurements, metadata, metric) do
# Report to your monitoring system
end
endExample: StatsD Reporter
defmodule Forge.Telemetry.StatsDReporter do
def attach do
metrics = Forge.Telemetry.Metrics.metrics()
Enum.each(metrics, fn metric ->
case metric.type do
:counter ->
:telemetry.attach(...)
:distribution ->
:telemetry.attach(...)
end
end)
end
end
Summary
Functions
Returns metrics for a specific category.
Returns counters only.
Returns distributions only.
Returns a list of metric definitions.
Functions
Returns metrics for a specific category.
Categories:
:pipeline- Pipeline-level metrics:stage- Stage execution metrics:measurement- Measurement computation metrics:storage- Storage operation metrics:dlq- Dead-letter queue metrics
Returns counters only.
Returns distributions only.
Returns a list of metric definitions.
Each metric is a map with:
:type-:counteror:distribution:name- Metric name:event_name- Telemetry event to listen to:measurement- Measurement key to extract:tags- List of metadata keys to use as tags:unit(distributions only) - Unit of measurement:buckets(distributions only) - Histogram bucket boundaries