Skip to content

Wrapper around ex_ray for OpenTrace in Elixir Phoenix

License

Notifications You must be signed in to change notification settings

sashman/phx_ex_ray

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PhxExRay

The first x is silent

Hex.pm

Wrapper around ex_ray for OpenTrace in Elixir Phoenix. Initial implementation based on the ex_ray_tracers example.

Installation

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.

Usage

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()
...

Plug Usage

# lib/my_app/endpoint.ex

...
plug Plug.RequestId         # needs a `x-request-id` header, generated by the RequestId plug
plug PhxExRay.Tracing.Plug
...

Controller Usage

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

Database Context Usage

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)

Http Client Usage

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)

Releases

No releases published

Packages

No packages published

Languages