Skip to content

Commit

Permalink
do not auto-declare metrics if prometheus not started
Browse files Browse the repository at this point in the history
  • Loading branch information
deadtrickster committed Aug 28, 2017
1 parent e909fcd commit e46623c
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/prometheus/metric.ex
Expand Up @@ -47,18 +47,22 @@ defmodule Prometheus.Metric do
defmacro __before_compile__(env) do
quote do
def __declare_prometheus_metrics__() do
unquote_splicing(
for metric <- @metrics do
declarations = Module.get_attribute(env.module, metric)
Module.delete_attribute(env.module, metric)
quote do
unquote_splicing(
for params <- declarations do
emit_create_metric(metric, params)
end)
:ok
end
end)
if List.keymember?(Application.started_applications(), :prometheus, 0) do
unquote_splicing(
for metric <- @metrics do
declarations = Module.get_attribute(env.module, metric)
Module.delete_attribute(env.module, metric)
quote do
unquote_splicing(
for params <- declarations do
emit_create_metric(metric, params)
end)
:ok
end
end)
else
:ok
end
end

unquote(
Expand Down

0 comments on commit e46623c

Please sign in to comment.