Packages
prom_ex
1.2.0
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
# credo:disable-for-this-file Credo.Check.Warning.IoInspect
defmodule PromEx.Debug do
@moduledoc """
This is a convenience module used for debugging and introspecting
telemetry events. Primarily used to ease the development of
PromEx itself.
"""
@doc """
Use this function to attach a debugger handler to a certain telemetry event.
"""
@spec attach_debugger(PromEx.telemetry_metrics() | list()) :: :ok | PromEx.telemetry_metrics()
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,
&__MODULE__.handle_event/4,
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,
&__MODULE__.handle_event/4,
config
)
:ok
end
@doc false
@spec handle_event([atom], map, map, any) :: any
def handle_event(event_name, event_measurement, event_metadata, config) do
IO.inspect(event_name, label: "---- EVENT NAME ----", limit: :infinity, structs: false)
IO.inspect(event_measurement, label: "---- EVENT MEASUREMENT ----", limit: :infinity, structs: false)
IO.inspect(event_metadata, label: "---- EVENT METADATA ----", limit: :infinity, structs: false)
IO.inspect(config, label: "---- CONFIG ----", limit: :infinity, structs: false)
end
end