-
Notifications
You must be signed in to change notification settings - Fork 68
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
Lack of documentation in Prometheus.Inject
#25
Comments
This one used to implement decorators, (see tests here https://github.com/deadtrickster/prometheus.ex/blob/master/test/injector_test.exs). For this it needs to walk over respective AST. Most of this file are workarounds for various syntaxes. |
I think it would be better to stick to single form of decorating blocks instead. I would propose to support only function callbacks (0-arity), as these do not need to provide macros and are flexible enough to handle all possible cases. For example current implementation do not support functions with headers. You can test it by yourself with this diff: diff --git a/test/injector_test.exs b/test/injector_test.exs
index ade3193..d9cdad7 100644
--- a/test/injector_test.exs
+++ b/test/injector_test.exs
@@ -31,6 +31,11 @@ defmodule Prometheus.InjectorTest do
IO.puts("fun2")
end
+ def fun_with_header(arg \\ 0)
+
+ def fun_with_header(arg) when is_binary(arg), do: IO.puts("fun_with_header binary")
+ def fun_with_header(_arg), do: IO.puts("fun_with_header other")
+
Injector.test do
def fun3() do
IO.puts("fun3") Or with private functions: diff --git a/test/injector_test.exs b/test/injector_test.exs
index ade3193..b18d8a1 100644
--- a/test/injector_test.exs
+++ b/test/injector_test.exs
@@ -39,6 +39,10 @@ defmodule Prometheus.InjectorTest do
IO.puts(e)
end
end
+
+ defp fun_p() do
+ IO.puts("fun_p")
+ end
end
def do_dangerous_work(x) do And second one gives you quite unintuitive message:
Because you have used So the only form available should be: Prometheus.Injector.inject(wrapper, fn -> … end) While I would go with slightly different API, which is: Prometheus.Injector.inject(callback, [before: &before_cb/0, after: &after_cb/1]) Where Or alternatively remove everything, and implement simple macros/functions to measure behaviours in respective metrics, as this would be IMHO the easiest solution. |
I would like to provide one, however it seems quite hard to deduce what is happening there.
The text was updated successfully, but these errors were encountered: