View Source SpandexPhoenix (spandex_phoenix v1.1.0)
A Plug wrapper for use in a Plug.Router or Phoenix.Endpoint to trace the entire request with Spandex.
NOTE: If you want to
usethis in combination withPlug.ErrorHandleror similar "wrapper" plugs, this one should be last so that it traces the effects of the other wrappers.
Phoenix integration:
defmodule MyAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
use SpandexPhoenix
# ...
endPlug integration:
defmodule MyApp.Router do
use Plug.Router
use SpandexPhoenix
# ...
end
options-for-use-macro
Options for use Macro
:filter_traces(arity-1 function reference)A function that takes a
Plug.Connand returnstruefor requests to be traced. For example, to only trace certain HTTP methods, you could do something like:defmodule MyAppWeb.Endpoint do use Phoenix.Endpoint, otp_app: :my_app use SpandexPhoenix, filter_traces: &__MODULE__.filter_traces/1 def filter_traces(conn) do conn.method in ~w(DELETE GET POST PUT) end endNOTE: Local references to functions in the module being defined (e.g.
&function/1) will not work because the module will not be compiled yet when the function is being referenced, so the function does not exist. Referencing the local function using&__MODULE__.function/1will work, however.Default: (a private function that always returns
true):span_name(String)The name to be used for the top level span.
Default:
“request”:tracer(Atom)The tracing module to be used for the trace.
Default:
Application.get_env(:spandex_phoenix, :tracer):customize_metadata(arity-1 function reference)A function that takes the
Plug.Connfor the current request and returns the desired span options to apply to the top-level span in the trace (as aKeyword). ThePlug.Connis normally evaluated just before the response is sent to the client, to ensure that the most-accurate metadata can be collected. In cases where there is an unhandled error, it may only represent the initial request without any response information.For example, if you want a particular path parameter to show its value in the
resourceinstead of its name, you should do something like:defmodule MyApp.Tracer do use Spandex.Tracer, otp_app: :my_app def customize_metadata(conn) do name = conn.path_params["name"] || "" conn |> SpandexPhoenix.default_metadata() |> Keyword.update(:resource, "", &String.replace(&1, ":name", name)) end end defmodule MyAppWeb.Endpoint do use Phoenix.Endpoint, otp_app: :my_app use SpandexPhoenix, customize_metadata: &MyApp.Tracer.customize_metadata/1 plug Router endNOTE: Local references to functions in the module being defined (e.g.
&function/1) will not work because the module will not be compiled yet when the function is being referenced, so the function does not exist. Referencing the local function using&__MODULE__.function/1will work, however.Default:
&SpandexPhoenix.default_metadata/1
Link to this section Summary
Functions
Default implementation of the filter_traces function
Link to this section Functions
@spec default_metadata(Plug.Conn.t()) :: Keyword.t()
@spec trace_all_requests(Plug.Conn.t()) :: true
Default implementation of the filter_traces function