Bugwatchbugwatch

SDK · Lua

Lua

Official Bugwatch SDK for Lua. A single init.lua file with no dependencies beyond LuaSocket (network) and LuaSec (HTTPS). Sends are synchronous — a capture posts inline, so there is nothing to wait on at exit. Works on Lua 5.1 and 5.3+.

Install

Lua
-- copy bugwatch/init.lua into your project
package.path = "path/to/?.lua;" .. package.path
local bugwatch = require("bugwatch.init")

Quickstart

Lua
local bugwatch = require("bugwatch.init")

math.randomseed(os.time())  -- recommended for unique event ids

bugwatch.init("https://bw-YOUR_KEY@bugwatch-api.loadmindx.com/api/1", {
  environment = "production",
  release = "1.0.0",
})

bugwatch.capture_message("Payment confirmed", "info")

local ok, err = pcall(function() error("boom") end)
if not ok then
  bugwatch.capture_exception(err)
end

bugwatch.flush()

Capture and re-raise

Lua
-- Any error inside the function is captured then re-raised
local safe = bugwatch.capture_fn(function()
  error("captured and re-raised")
end)

local ok, err = pcall(safe)
-- ok == false, err == "captured and re-raised"

capture_fn wraps any function: the error is reported to Bugwatch, then re-raised so your control flow is unchanged.

API

APIDescription
init(dsn, opts) -> bool, err?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(err) -> id?Capture an error string, or a table {type=, value=}.
capture_fn(fn) -> fnWrap a function: errors are captured then re-raised.
set_tag(k, v)Set a tag on subsequent events.
set_user(id, extra)Set user context (PII stripped).
add_breadcrumb({message=, category=})Append to the trail (max 100).
clear_scope()Clear tags, user and breadcrumbs.
flush()No-op — sends are synchronous.
is_initialized() -> boolCheck init state.

Init options

APIDescription
environmentEnvironment name sent with every event.
releaseRelease/version identifier.
sample_rate0.0–1.0 fraction of events to keep.
debugLog send results to stderr.
allow_httpSet true to allow plain HTTP DSNs (tests only).