> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squasher.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust SDK

> Capture Rust errors, messages, panic hooks, tags, users, breadcrumbs, and telemetry with the Squasher Rust SDK.

Use the Rust SDK when you want native error capture from a Rust service without wiring an OpenTelemetry exporter first.

## Install

```bash theme={null}
cargo add squasher
```

## Initialize

```rust main.rs theme={null}
use std::time::Duration;

fn main() {
    squasher::init(squasher::Config {
        api_key: std::env::var("SQUASHER_API_KEY").unwrap_or_default(),
        project_id: std::env::var("SQUASHER_PROJECT_ID").unwrap_or_default(),
        environment: std::env::var("SQUASHER_ENV").ok(),
        release: std::env::var("GIT_SHA").ok(),
        ..Default::default()
    });

    squasher::install_panic_hook();

    squasher::capture_message("service started", squasher::Level::Info);
    squasher::flush(Duration::from_secs(5));
}
```

Empty `api_key` or `project_id` values put the SDK in disabled mode, so local development can keep the same initialization path without sending events.

The SDK batches buffered events and automatically splits multi-event request bodies at 1 MB. An
individual event larger than that remains a single request rather than being silently dropped.

## Capture errors

```rust theme={null}
use std::time::Duration;

fn read_config() {
    if let Err(error) = std::fs::read_to_string("missing.toml") {
        squasher::capture_error(&error, None);
        squasher::flush(Duration::from_secs(5));
    }
}
```

## Add context

```rust theme={null}
use std::collections::HashMap;

squasher::set_tag("service", "checkout");
squasher::set_tags(HashMap::from([
    ("environment".to_string(), "production".to_string()),
]));

squasher::set_user(Some(squasher::User {
    id: Some("user_123".to_string()),
    email: None,
    username: None,
    ip_address: None,
}));
```

## Trace identifiers

The SDK can mint Squasher-compatible trace and span ids for custom telemetry:

```rust theme={null}
let trace_id = squasher::create_trace_id();
let span_id = squasher::create_span_id();
```

## Agent handoff

```text theme={null}
Install the Squasher Rust SDK. Initialize once from SQUASHER_API_KEY and SQUASHER_PROJECT_ID, install the panic hook, add safe tags/user context, flush before process exit, and verify with one captured message or error.
```

## Related docs

* [Rust integration](/integrations/rust)
* [OpenTelemetry](/integrations/opentelemetry)
* [HTTP API](/integrations/http-api)
