Bugwatchbugwatch

SDK · Rust

Rust

Official Bugwatch SDK for Rust. Only serde_json as a dependency — networking uses the system curl, so the SDK stays small and portable. Events are sent on background threads; a slow or down Bugwatch server never stalls your application.

Install

Cargo.toml
[dependencies]
bugwatch-sdk = "0.1.0"

Quickstart

Rust
use bugwatch::{init, capture_message, capture_exception, flush, Level};
use std::collections::HashMap;

fn main() {
    let mut opts = HashMap::new();
    opts.insert("environment", serde_json::json!("production"));
    opts.insert("release", serde_json::json!("1.0.0"));
    init("https://bw-YOUR_KEY@bugwatch-api.loadmindx.com/api/1", Some(opts)).unwrap();

    let _id = capture_message("Payment confirmed", Level::Info);

    let bt = std::backtrace::Backtrace::capture();
    let _id = capture_exception("Panic", "index out of bounds", Some(&bt));

    // IMPORTANT: join pending sender threads before exit
    flush();
}

Context

Rust
bugwatch::set_tag("region", "eu-west");
bugwatch::set_user("42", None);

bugwatch::add_breadcrumb(bugwatch::Breadcrumb {
    category: Some("db".into()),
    message: "query users".into(),
    ..Default::default()
});

bugwatch::clear_scope();

Breadcrumbs are capped at 100 and attached to every event. The user context strips email, ip_address, ip and username before anything leaves the process.

API

APIDescription
init(dsn, options) -> ResultParse the DSN, validate HTTPS (unless allow_http), store config. Errors if called twice.
capture_message(msg, level) -> Option<String>Capture a message: debug, info, warning, error or fatal. Returns the client-generated event id.
capture_exception(type, value, backtrace) -> Option<String>Capture an exception with an optional std::backtrace::Backtrace.
set_tag(k, v)Set a tag on subsequent events.
set_user(id, extra)Set user context (PII stripped).
add_breadcrumb(Breadcrumb)Append to the breadcrumb trail (max 100).
clear_scope()Clear tags, user, context and breadcrumbs.
flush()Join pending sender threads. Call it before the process exits.
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 failures to stderr.
allow_httpSet true to allow plain HTTP DSNs (tests only).