bugwatch-sdk-js
v0.1.1
Published
Official dependency-free JavaScript SDK for Bugwatch error tracking (browser + Node.js)
Maintainers
Readme
bugwatch-sdk-js
Official dependency-free JavaScript SDK for Bugwatch error tracking. Works in the browser and in Node.js (>=14), with no build step and no runtime dependencies.
It defines the global Bugwatch object and also ships CommonJS + ESM
entry points with TypeScript types. Transport is fetch() with
keepalive: true only — never sendBeacon (it cannot set
X-Bugwatch-Key). HTTPS is required unless allowHttp: true. Email, IP
and usernames are not sent unless sendDefaultPii: true.
Bugwatch.flush() waits for in-flight requests.
Install
npm install bugwatch-sdk-jsOr copy bugwatch.js to your server and include it before your app code:
<script src="/static/bugwatch.js"></script>Usage
Browser (global)
<script src="/static/bugwatch.js"></script>
<script>
Bugwatch.init({
dsn: "https://[email protected]/api/1",
environment: "production",
release: "1.2.3",
sampleRate: 1.0
});
try {
throw new Error("Payment declined");
} catch (err) {
Bugwatch.captureException(err, {
tags: { module: "checkout" },
user: { id: "42", email: "[email protected]" }
});
}
Bugwatch.captureMessage("Cart confirmed", {
level: "info",
tags: { feature: "cart" }
});
Bugwatch.flush();
</script>Node.js (CommonJS)
const Bugwatch = require("bugwatch-sdk-js");
Bugwatch.init({
dsn: "https://[email protected]/api/1",
environment: "production"
});
Bugwatch.captureException(new Error("boom"));
Bugwatch.flush();ESM / TypeScript
import Bugwatch from "bugwatch-sdk-js";
Bugwatch.init({
dsn: "https://[email protected]/api/1"
});
const eventId = Bugwatch.captureException(new Error("boom"));API
| Method | Description |
| --- | --- |
| Bugwatch.init(options) | Configure the SDK. Returns true when the DSN was accepted. |
| Bugwatch.captureException(error, {tags, user}) | Capture an exception (Error or string). Returns event_id or null. |
| Bugwatch.captureMessage(message, {level, tags, user}) | Capture a message. Returns event_id or null. |
| Bugwatch.setUser(user) | Set the current user. |
| Bugwatch.setTag(key, value) | Add a current tag. |
| Bugwatch.setContext(context) | Set context (including an optional request key). |
| Bugwatch.flush(timeoutMs) | Wait for in-flight sends (default 5000 ms). |
init options: dsn, environment, release, sampleRate, debug,
sendDefaultPii, allowHttp.
DSN format
https://{public_key}@{host}/api/{project_id}The SDK POSTs JSON to {dsn}/store/ with header
X-Bugwatch-Key: {public_key}. platform is "javascript"; the
stacktrace is parsed from error.stack.
Development
npm test # run the test suite
npm run prepublishOnly # runs before every npm publishLicense
MIT
