Packages
prom_ex
0.1.5-alpha
1.12.0
1.11.0
1.10.0
1.9.0
1.8.0
1.7.1
1.7.0
retired
1.6.0
1.5.0
1.4.1
1.4.0
1.3.0
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.1
1.0.0
0.1.15-beta
0.1.14-beta
0.1.13-beta
0.1.12-beta
0.1.11-alpha
0.1.10-alpha
0.1.9-alpha
0.1.8-alpha
0.1.7-alpha
0.1.6-alpha
0.1.5-alpha
0.1.4-alpha
0.1.3-alpha
0.1.2-alpha
0.1.1-alpha
0.1.0-alpha
Prometheus metrics and Grafana dashboards for all of your favorite Elixir libraries
Current section
Files
Jump to
Current section
Files
lib/prom_ex/debug.ex
defmodule PromEx.Debug do
# credo:disable-for-this-file Credo.Check.Warning.IoInspect
@moduledoc """
This is a convenience module used for debugging and introspecting
telemetry events. Primarily used to ease for development or
PromEx itself.
"""
@typep metrics_types :: PromEx.MetricTypes.Event.t() | PromEx.MetricTypes.Manual.t() | PromEx.MetricTypes.Polling.t()
@doc """
Use this function to attach a debugger handler to a certain telemetry event. This
function will also return the
"""
@spec attach_debugger(metrics_types() | list()) :: :ok | metrics_types()
def attach_debugger(%_{event_name: event_name} = telemetry_metric_def) do
random_id =
10
|> :crypto.strong_rand_bytes()
|> Base.url_encode64()
|> binary_part(0, 10)
config = %{
handler_id: random_id,
telemetry_metric: telemetry_metric_def
}
:telemetry.attach(
random_id,
event_name,
fn event_name, event_measurement, event_metadata, config ->
IO.inspect(event_name, label: "---- EVENT NAME ----")
IO.inspect(event_measurement, label: "---- EVENT MEASUREMENT ----")
IO.inspect(event_metadata, label: "---- EVENT METADATA ----")
IO.inspect(config, label: "---- CONFIG ----")
end,
config
)
telemetry_metric_def
end
def attach_debugger(event) when is_list(event) do
random_id =
10
|> :crypto.strong_rand_bytes()
|> Base.url_encode64()
|> binary_part(0, 10)
config = %{
handler_id: random_id,
event: event
}
:telemetry.attach(
random_id,
event,
fn event_name, event_measurement, event_metadata, config ->
IO.inspect(event_name, label: "---- EVENT NAME ----")
IO.inspect(event_measurement, label: "---- EVENT MEASUREMENT ----")
IO.inspect(event_metadata, label: "---- EVENT METADATA ----")
IO.inspect(config, label: "---- CONFIG ----")
end,
config
)
:ok
end
end