Current section

Files

Jump to
absinthe_metrics lib backends prometheus_label_histogram.ex
Raw

lib/backends/prometheus_label_histogram.ex

defmodule AbsintheMetrics.Backend.PrometheusLabelHistogram do
@behaviour AbsintheMetrics
use Prometheus
def field(object, field, buckets: buckets) do
true = Histogram.declare([name: to_metric(object, field),
labels: [:status],
buckets: buckets,
help: "Metrics for GraphQL resolver: #{to_metric(object, field)}"])
end
def instrument(object, field, {status, _}, time), do: Histogram.observe([name: to_metric(object, field), labels: [status]], time)
defp to_metric(:query, field), do: "#{field}_duration_microseconds"
defp to_metric(object, field), do: "#{object}_#{field}_duration_microseconds" |> String.to_atom()
end