# `Zharp`
[🔗](https://github.com/zharp-io/zharp-elixir-lib/blob/v0.1.0/lib/zharp.ex#L1)

Zharp Application Monitoring for Elixir.

    # mix.exs
    {:zharp, "~> 0.1"}

    # lib/my_app_web/endpoint.ex (Phoenix), or your Plug router
    plug Zharp.Plug

and `ZHARP_KEY` in the environment (or `config :zharp, key: ...` in `config/runtime.exs`).
`mix igniter.install zharp` does all of it.

Requests (Phoenix, LiveView, Plug on Bandit or Cowboy), Ecto queries, outgoing HTTP (Finch,
Req, Tesla), Oban jobs and Absinthe operations are traced; errors become Zharp issues, each
once, with the code that ran, including processes that crash outside a request (a GenServer,
a Task); failed queries carry their query; each log line written during a request ends with
its trace and span id for the Zharp agent (`ZHARP_LOGS=true` sends the logs from the SDK
instead). Built on OpenTelemetry Erlang: spans you create with `OpenTelemetry.Tracer` are sent too.

# `active?`

Whether Zharp started (it has a key and isn't disabled).

# `capture_exception`

Reports an exception you rescued, as a handled error with the trace, user and session of the
current request. Pass the stacktrace so Zharp shows where it happened:

    rescue
      error ->
        Zharp.capture_exception(error, stacktrace: __STACKTRACE__, extra: %{order_id: order.id})

Options: `stacktrace:`, `extra:` (attributes), `handled:` (default true). Any value can be
reported: an Erlang error (`:badarg` becomes `ArgumentError`), an exit (`kind: :exit`) or a throw.

# `clear_user`

Forgets the user set in this process.

# `flush`

Sends everything queued now: at the end of a script or a job.

# `log`

A log line sent from the SDK, whatever `ZHARP_LOGS` says: the lines you want in Zharp from the
code itself. Level: `:debug`, `:info`, `:warning`, `:error`.

    Zharp.log(:info, "order paid", order_id: 42)

# `options`

The settings Zharp is running with, or nil when it isn't.

# `set_tag`

An attribute on every log and error from now on (nil removes it).

# `set_user`

The user of the current request (`enduser.id`, `enduser.email`, `enduser.name`), on its span,
logs and errors from here on, and in Tasks started from this process. A browser or mobile app
using a Zharp SDK already sends its user with each request.

    Zharp.set_user(id: user.id, email: user.email)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
