Skip to content

Commit

Permalink
Phoenix Plugin: Correctly support multiple endpoints (#254)
Browse files Browse the repository at this point in the history
* Phoenix Plugin: Correctly support multiple endpoints

* Normalize the endpoint module tag value

* Phoenix plugin: Normalize the handler module tag
  • Loading branch information
joshk authored Oct 24, 2024
1 parent 0eec6cb commit 98efa96
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/prom_ex/plugins/phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ if Code.ensure_loaded?(Phoenix) do
end

defp endpoint_info(metric_prefix, opts) do
# Fetch user options
phoenix_endpoint = Keyword.get(opts, :endpoint) || Keyword.get(opts, :endpoints)
keep_function_filter = keep_endpoint_metrics(phoenix_endpoint)
phoenix_endpoints = normalize_endpoint(opts)

keep_function_filter = keep_endpoint_metrics(phoenix_endpoints)

Event.build(
:phoenix_endpoint_metrics,
Expand All @@ -218,8 +218,17 @@ if Code.ensure_loaded?(Phoenix) do
)
end

defp keep_endpoint_metrics(phoenix_endpoint) when is_atom(phoenix_endpoint) do
keep_endpoint_metrics([phoenix_endpoint])
defp normalize_endpoint(opts) do
cond do
endpoint = Keyword.get(opts, :endpoint) ->
[endpoint]

endpoints = Keyword.get(opts, :endpoints) ->
Enum.map(endpoints, fn e -> elem(e, 0) end)

true ->
[]
end
end

defp keep_endpoint_metrics(phoenix_endpoints) do
Expand All @@ -242,7 +251,7 @@ if Code.ensure_loaded?(Phoenix) do
end

%{
endpoint: module,
endpoint: normalize_module_name(module),
url: module.url(),
port: port
}
Expand Down Expand Up @@ -337,7 +346,7 @@ if Code.ensure_loaded?(Phoenix) do
%{
endpoint: normalize_module_name(endpoint),
event: normalize_event_name.(event),
handler: handler
handler: normalize_module_name(handler)
}
end,
tags: [:endpoint, :handler, :event],
Expand Down

0 comments on commit 98efa96

Please sign in to comment.