Bugwatchbugwatch

SDK · Perl

Perl

Official Bugwatch SDK for Perl. Core-only — no CPAN dependencies (IO::Socket::SSL is used for HTTPS when present). Sends are synchronous — a capture posts inline, so there is nothing to wait on at exit.

Install

Perl
use lib 'path/to/lib';
use Bugwatch;

Quickstart

Perl
use Bugwatch;

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

Bugwatch->capture_message("Payment confirmed", "info");

my $ok = eval {
    die "boom\n";
    1;
};
Bugwatch->capture_exception($@) unless $ok;

Bugwatch->flush();

Capture and re-raise

Perl
my $safe = Bugwatch->capture_fn(sub {
    die "captured and re-raised";
});

my $ok = eval { $safe->(); 1 };
# $ok is false, $@ is "captured and re-raised"

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

Context

Perl
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

APIDescription
init(dsn, opts) -> (1, undef) | (undef, 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 hashref {type =>, value =>}.
capture_fn(coderef) -> coderefWrap a coderef: die is 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(hashref)Append to the trail (max 100).
clear_scope()Clear tags, user and breadcrumbs.
flush()No-op — sends are synchronous.
is_initialized()Check 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).