The first x is silent
Wrapper around ex_ray for OpenTrace in Elixir Phoenix. Initial implementation based on the ex_ray_tracers example.
If available in Hex, the package can be installed
by adding phx_ex_ray
to your list of dependencies in mix.exs
:
def deps do
[
{:phx_ex_ray, "~> 0.1"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/phx_ex_ray.
Configure otter:
config :otter,
zipkin_collector_uri: 'http://127.0.0.1:9411/api/v1/spans',
zipkin_tag_host_service: "MyApp"
zipkin_collector_uri
must be a char list
Configure application:
# application.ex
...
ExRay.Store.create()
...
# lib/my_app/endpoint.ex
...
plug Plug.RequestId # needs a `x-request-id` header, generated by the RequestId plug
plug PhxExRay.Tracing.Plug
...
Cross controller set up:
# lib/my_app/my_app_web.ex
def controller do
quote do
...
import PhxExRay.Span
...
end
end
Then in a specific controller:
use PhxExRay.Span, :controller
@trace kind: :action
def index(conn, _params) do
...
end
In a context, or any file where you use alias MyApp.Repo
:
use PhxExRay.Span, {:context, MyApp.Repo}
...
@trace query: :list_all_users, kind: :all, queryable: User
def list_users() do
Repo.all(User)
end
# or
@trace query: :get_user_or_explode, sql: "SELECT * FROM users WHERE (id = X)"
def get_user!(id), do: Repo.get!(User, id)
ex_ray provides integration for http client tracing. Additional config required to specific which http client you want to use:
config :otter,
...
http_client: (:ibrowse|:httpc|:hackney)