Help with implementing a macro

Okay, I can see that I have no business writing macros at my level of understanding since I can’t even follow these responses :joy:. I was trying to write a module for testing that simulates the instrument/3 macro in Phoenix.Endpoint.Instrument so I can test my instrumenters. The macro should produce the following code:

  def instrument(:my_event, compile, runtime, fun) do
    result = MyModule.my_event(:start, compile, runtime)
 
    start = :erlang.monotonic_time()
    try do
      fun.()
    after
      diff = :erlang.monotonic_time() - start
      MyModule.my_event(:stop, diff, result)
    end
  end