SDK · Elixir
Elixir
Official Bugwatch SDK for Elixir. No external dependencies — networking uses the stdlib :httpc and :crypto. The SDK runs as a supervised GenServer; events are sent in background Tasks, so a slow or down Bugwatch server never stalls your application.
Install
mix.exs
def deps do
[{:bugwatch, "~> 0.1.0"}]
endQuickstart
Elixir
{:ok, _} = Bugwatch.start_link()
:ok = Bugwatch.setup("https://bw-YOUR_KEY@bugwatch-api.loadmindx.com/api/1",
environment: "production",
release: "1.0.0"
)
Bugwatch.capture_message("Payment confirmed", "info")
try do
raise RuntimeError, "boom"
rescue
e ->
Bugwatch.capture_exception(
e.__struct__ |> Atom.to_string() |> String.trim_leading("Elixir."),
Exception.message(e)
)
end
Bugwatch.flush()Context
Elixir
Bugwatch.set_tag("region", "eu-west")
Bugwatch.set_user("42", %{"plan" => "pro"})
Bugwatch.add_breadcrumb(%{"message" => "clicked", "category" => "ui"})
Bugwatch.clear_scope()The user context strips email, ip_address, ip and username before anything leaves the process. Breadcrumbs are capped at 100.
API
| API | Description |
|---|---|
| start_link/1 | Start the SDK GenServer (auto-started by setup/2 if absent). |
| setup(dsn, opts) -> :ok | {:error, reason} | Parse the DSN, validate HTTPS (unless allow_http). Errors if called twice. |
| capture_message(msg, level) -> id? | Capture a message: debug, info, warning, error or fatal. |
| capture_exception(type, value, level) -> id? | Capture an exception type + value. |
| set_tag(k, v) | Set a tag on subsequent events. |
| set_user(id, extra) | Set user context (PII stripped). |
| add_breadcrumb(map) | Append to the trail (max 100). |
| clear_scope() | Clear tags, user and breadcrumbs. |
| flush() | Wait for pending async sends. Call it before the script exits. |
| initialized?() | Check init state. |
Setup options
| API | Description |
|---|---|
| environment | Environment name sent with every event. |
| release | Release/version identifier. |
| sample_rate | 0.0–1.0 fraction of events to keep. |
| debug | Log send failures with IO.warn. |
| allow_http | Set true to allow plain HTTP DSNs (tests only). |
