Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phoenix Plugin: Correctly support multiple endpoints #254

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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