Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 1.4 KB

README.md

File metadata and controls

43 lines (33 loc) · 1.4 KB

PlugOpenTracing

Build Status Hex.pm Documentation

An Elixir Plug for adding OpenTracing instrumentation.

Usage

Update your mix.exs file and run mix deps.get.

defp deps do
  [{:plug_opentracing, "~> 0.1"}]
end

Add the plug to a pipeline. In this case we will look for the uber-trace-id header to exist. If so, it is split on : and the first and second values are used as the trace_id and parent_id when creating the span.

defmodule MyPhoenixApp.MyController do
  use MyPhoenixApp.Web, :controller
  alias Plug.Conn.Status

  plug PlugOpenTracing, trace_id: 'uber-trace-id'
  plug :action

  def index(conn, _params) do
    conn
    |> put_status(Status.code :ok)
  end
end

The created span can be accessed using conn.assigns[:trace_span]. This is useful when you want to use this span as the parent of another span in your request, or if you want to add tags/logs to the span before it is finished.

The request span will be finished at the end of your request using a callback, which will send it to the Jaeger or Zipkin endpoint you've set up in your config.