Skip to content

Update rpc.ex #1331

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

Open
wants to merge 1 commit into
base: main
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
10 changes: 9 additions & 1 deletion lib/realtime/rpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ defmodule Realtime.Rpc do
"""
import Realtime.Logs
alias Realtime.Telemetry
require Logger

@doc """
Calls external node using :rpc.call/5 and collects telemetry
"""
@spec call(atom(), atom(), atom(), any(), keyword()) :: any()
def call(node, mod, func, args, opts \\ []) do
Logger.debug("Rpc.call called: #{inspect({node, mod, func, args})}")
timeout = Keyword.get(opts, :timeout, Application.get_env(:realtime, :rpc_timeout))
{latency, response} = :timer.tc(fn -> :rpc.call(node, mod, func, args, timeout) end)

success = case response do
{:badrpc, _} -> false
_ -> true
end

Telemetry.execute(
[:realtime, :rpc],
%{latency: latency},
%{mod: mod, func: func, target_node: node, origin_node: node()}
%{mod: mod, func: func, target_node: node, origin_node: node(), success: success}
)

response
Expand All @@ -28,6 +35,7 @@ defmodule Realtime.Rpc do
@spec enhanced_call(atom(), atom(), atom(), any(), keyword()) ::
{:ok, any()} | {:error, :rpc_error, term()} | {:error, term()}
def enhanced_call(node, mod, func, args \\ [], opts \\ []) do
Logger.debug("Rpc.enhanced_call called: #{inspect({node, mod, func, args})}")
timeout = Keyword.get(opts, :timeout, Application.get_env(:realtime, :rpc_timeout))

with {latency, response} <-
Expand Down