PryIn v1.5.0 PryIn View Source

PryIn is a performance metrics platform for your Phoenix application. This is the main entry point for the client library.

Link to this section Summary

Functions

Drops a running trace

Collects metrics about custom code

Join a process into a running trace

Add context to a running trace

Add the current value for a metric

Link to this section Functions

Link to this function drop_trace(pid \\ self()) View Source

Drops a running trace.

Use this if you don’t want a trace being forwarded to PryIn. Must be called after the trace was started.

Example:

def index(conn, params) do
  PryIn.drop_trace()
  ...
end
Link to this macro instrument(key, opts \\ [], list) View Source (macro)

Collects metrics about custom code.

Wrap any code in to have it’s runtime reported to PryIn. The key argument will be present in the web ui, so you can identify the measurement.

Note that you need to require PryIn before calling the instrument macro.

Metrics are only collected inside of tracked interactions.

Example:

def index(conn, params) do
  api_result = PryIn.instrument("foo_api_call") do
    FooApi.call(%{user_id: conn.assigns.user.id})
  end
...
end
Link to this function join_trace(parent_pid, child_pid) View Source

Join a process into a running trace.

Use this to add metrics from a child process to a parent process. Example:

def index(conn, params) do
  ...
  parent_pid = self()
  task = Task.async(fn ->
    PryIn.join_trace(parent_pid, self())
    Repo.all(User)
    ...
  end)
  Task.await(task)
  ...
end

Without calling join_trace here, the Repo.all call would not be added to the trace of the index action, as it happens in a different process.

Link to this function put_context(key, value, pid \\ self()) View Source

Add context to a running trace.

Both arguments need to implement the String.Chars protocol, so to_string/1 can be called with them.

Example:

def index(conn, params) do
  PryIn.put_context(:user_id, conn.assigns.user.id)
...
end
Link to this function track_metric(label, value, opts \\ %{}) View Source

Add the current value for a metric.

This is independent of a running trace.

The first argument is a (string) label that can be chosen freely.

The second argument is the actual value.

Possible keys for opts are currently:

  • :context: A map of additional metadata.
  • :sample_rate: If you don’t want to include this metric every time, supply a sample rate between 0 and 1.

Example:

PryIn.track_metric("genserver state length", length(state.some_list), context: %{some_key: "some_value"})