absinthe_metrics

Pluggable metrics for Absinthe based GraphQL backends

Latest version: 1.1.0 registry icon
Maintenance score
0
Safety score
0
Popularity score
71
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High
1.1.0 0 0 0 0
1.0.0 0 0 0 0
0.9.0 0 0 0 0
0.8.0 0 0 0 0
0.7.0 0 0 0 0
0.6.0 0 0 0 0
0.5.0 0 0 0 0
0.4.0 0 0 0 0
0.3.0 0 0 0 0
0.2.0 0 0 0 0
0.1.0 0 0 0 0

Stability
Latest release:

1.1.0 - this version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



AbsintheMetrics

Build Status

AbsintheMetrics provides time (or counter) based metrics for your Absinthe resolvers to allow you to keep track of where your queries are spending their time.

Usage is fairly straight forward,

defmodule MyApp.Instrumenter do
  use AbsintheMetrics,
    adapter: AbsintheMetrics.Backend.PrometheusHistogram,
    # See prometheus.ex for more examples
    arguments: [buckets: {:exponential, 250, 1.5, 7}]
end

defmodule MyApp.Schema do
  use Absinthe.Schema
  def middleware(middlewares, field, object) do
    MyApp.Instrumenter.instrument(middlewares, field, object)
  end
end

# in application.ex

defmodule MyApp do
  def start(_type, _args) do
    # initialize all available metrics in your schema
    MyApp.Instrumenter.install(MyApp.Schema)
    # ...
  end
end

How metrics are gathered depends on the backend, but for PrometheusHistogram the format is #{object}_#{field}_duration_microseconds or query_field_duration_microseconds for root queries.

Adding backends

Adding additional backends is pretty straight forward, you just need to implement the AbsintheMetrics behaviour,

defmodule LogBackend do
  @behaviour AbsintheMetrics
  require Logger

  # Called during application start to allow you to register
  # fields with your TSDB
  def field(object, field, _args \\ []) do
    Logger.info("install field #{object}_#{field}")
  end

  # Called every time a value is observed
  # status can be :ok or :error
  def instrument(object, field, {status, _result}, time) do
    metric = "#{object}_#{field}"
    case status do
      :error -> Logger.warn("#{metric} failed (took: #{inspect time})")
      :ok -> Logger.info("#{metric} took: #{inspect time}")
    end
  end
end

Installation

If available in Hex, the package can be installed by adding absinthe_metrics to your list of dependencies in mix.exs:

def deps do
  [
    {:absinthe_metrics, "~> 0.9.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/absinthe_metrics.