Skip to main content

Crate errsight

Crate errsight 

Source
Expand description

§ErrSight — Rust client

Captures panics, errors, and log/tracing events and ships them to the ErrSight API from a background thread. Capture is non-blocking; delivery is batched, bounded, and drained on shutdown.

use errsight::{Config, Level};

fn main() {
    // Keep the guard alive for the life of the process — dropping it flushes
    // and shuts the client down.
    let _guard = errsight::init(
        Config::builder()
            .api_key("elp_your_key")
            .environment("production")
            .release(env!("CARGO_PKG_VERSION"))
            .build(),
    );

    errsight::configure_scope(|scope| {
        scope.set_tag("service", "checkout");
    });

    if let Err(e) = do_work() {
        // `e` is a boxed trait object here, so use the `_dyn` variant.
        // For a concrete error type, `capture_error(&err)` also records
        // its type name.
        errsight::capture_error_dyn(&*e);
    }

    errsight::capture_message("checkout completed", Level::Info);
}

fn do_work() -> Result<(), Box<dyn std::error::Error>> {
    Ok(())
}

§What gets captured

  • Panics — via a hook installed on init (opt out with ConfigBuilder::panic_hook). Captured as fatal with the panic backtrace.
  • Errorscapture_error records the message, type name, the source() cause chain, and a backtrace (captured at the call site; enable the anyhow feature and use capture_anyhow for the error’s origin backtrace).
  • Messagescapture_message for arbitrary log lines.
  • log / tracing — optional integrations behind the log and tracing features.

§Configuration

Build a Config explicitly or seed it from ERRSIGHT_* environment variables (see Config::from_env). The client is a cheap no-op until a non-blank API key is present, so capture_* calls are safe to ship unconditionally.

Re-exports§

pub use integrations::anyhow::capture_anyhow;anyhow

Modules§

integrationsanyhow or log or tracing
Optional integrations, each behind a cargo feature.
panic
Panic capture.

Structs§

Breadcrumb
A timestamped activity record leading up to an event. The backend keeps the most recent 50.
Cause
An entry in an error’s source() / cause chain. The backend surfaces these on the issue detail page as “caused by”.
Client
The capture/transport client. Held behind an Arc; cheap to share.
ClientGuard
Guard returned by init. Flushes and closes the client on drop.
Config
Immutable client configuration. Build with Config::builder or Config::from_env; once handed to crate::init it lives behind an Arc and never changes.
ConfigBuilder
Fluent builder for Config. Every setter returns self; finish with ConfigBuilder::build.
Event
A single error/log event, serialized to the JSON the backend ingests.
Frame
One resolved stack frame. Shipped inside metadata["exception_frames"]. in_app frames (your code, not dependencies) are the ones the UI highlights and shows source context for.
Scope
Ambient context layered onto events: the current user, string tags, and a bounded breadcrumb trail. Cheap to clone (that’s how the hub forks scopes).
User
The signed-in user an event is attributed to. All fields optional; the backend derives a display identifier from idemailusername.

Enums§

Level
An event’s severity. Variants are ordered Debug < Info < Warning < Error < Fatal, which is what makes level >= config.min_level a correct threshold check.
SendOutcome
What happened to a send attempt. The worker uses this to decide whether to drop the batch, pause, or just log.

Constants§

VERSION
The SDK version (CARGO_PKG_VERSION). Sent in the User-Agent.

Traits§

Transport
Sends a serialized JSON batch to the ingestion endpoint.

Functions§

add_breadcrumb
Add a breadcrumb to the current scope.
capture_error
Capture a concrete error at error level, recording its type name, message, source() cause chain, and a backtrace captured at this call site.
capture_error_at_level
Capture a concrete error at an explicit level (e.g. a recovered error you want recorded as a warning).
capture_error_dyn
Like capture_error but for a &dyn Error. The concrete type name isn’t recoverable from a trait object, so exception_class is omitted.
capture_event
Capture a fully-constructed Event for advanced use. Applies the min_level gate, config defaults, current scope, and before_send.
capture_message
Capture a free-form message at the given level. Returns the event’s ingestion_id if it was queued. No-op (returns None) when disabled or below min_level.
close
Shut down the global client, draining queued events. Idempotent. Called for you when the init guard drops.
configure_scope
Run f against the current effective scope, mutating in place. If a with_scope frame is active it’s mutated; otherwise the base scope is.
flush
Block until queued events are delivered, or timeout elapses (default: the configured shutdown timeout). Returns true if the flush was acknowledged.
init
Initialize the global client and return a guard that flushes and shuts it down when dropped.
register_panic_hook
Install the panic-capturing hook manually. Idempotent; normally done for you by init. Useful if you construct a Client without init, or set panic_hook(false) and want to install it later.
with_scope
Push a fresh scope frame (forked from the current effective scope), run body, then pop — even on panic. Mutations made inside via configure_scope apply only to the duration of the block.

Type Aliases§

BeforeSend
A before_send hook: final-mile filter run on the calling thread before an event is queued. Return Some(event) (possibly mutated) to send, or None to drop.