I’m wrapping my Appsignal instrumentation and everything works fine.
def handle_event("submit", %{"waitlist" => params}, socket) do
live_view_action(__MODULE__, "submit", socket, fn ->
{:noreply, socket}
end)
end
I wanted to move this to a decorator so I could do something like this:
@decorate instrument("submit")
def handle_event("submit", %{"waitlist" => params}, socket) do
{:noreply, socket}
end
# And in my decorator:
import Appsignal.Phoenix.LiveView, only: [live_view_action: 4]
def get_socket(context) do
# Context looks like this:
# %Decorator.Decorate.Context{
# args: [
# "submit",
# {:%{}, [line: 23], [{"waitlist", {:params, [line: 23], nil}}]},
# {:socket, [line: 23], nil}
# ],
# arity: 3,
# module: HelloWorld.ComingSoonLive,
# name: :handle_event
# }
Enum.find(context.args, fn arg ->
[{_, type} | _] = IEx.Info.info(arg)
if type == "tuple" && elem(arg, 0) == :socket do
arg
end
end)
end
def instrument(name, body, context) do
quote do
socket = unquote(get_socket(context))
live_view_action(unquote(context.module), unquote(name), socket, fn ->
unquote(body)
end)
end
end
socket
is always nil
in the context at compilation time so I can’t even run my project.
How can I use the value of socket at runtime where I know the socket
won’t be nil
?