Zharp Application Monitoring for Elixir.
# mix.exs
{:zharp, "~> 0.1"}
# lib/my_app_web/endpoint.ex (Phoenix), or your Plug router
plug Zharp.Plugand 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.
Summary
Functions
Whether Zharp started (it has a key and isn't disabled).
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
Forgets the user set in this process.
Sends everything queued now: at the end of a script or a job.
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.
The settings Zharp is running with, or nil when it isn't.
An attribute on every log and error from now on (nil removes it).
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.
Functions
Whether Zharp started (it has a key and isn't disabled).
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.
Forgets the user set in this process.
Sends everything queued now: at the end of a script or a job.
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)
The settings Zharp is running with, or nil when it isn't.
An attribute on every log and error from now on (nil removes it).
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)