# errorgap for Rust

See [index.md](./index.md) for API details and the placeholder values (`ERRORGAP_API_KEY`, `ERRORGAP_ENDPOINT`, `ERRORGAP_PROJECT_SLUG`).

SDK source: `github.com/errorgaphq/errorgap-rust` · current version: `0.2.0`. Requires Rust 1.75+.

## Install

```toml
[dependencies]
errorgap = "0.2"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
```

## Configure

```rust
use errorgap::Configuration;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    errorgap::init(
        Configuration::builder()
            .endpoint(std::env::var("ERRORGAP_ENDPOINT")?)
            .project_slug(std::env::var("ERRORGAP_PROJECT_SLUG")?)
            .api_key(std::env::var("ERRORGAP_API_KEY")?)
            .build()?,
    )?;

    run_app().await?;

    errorgap::flush().await;
    errorgap::shutdown().await;
    Ok(())
}
```

For axum / tonic, wrap with the tower layer (default feature):

```rust
let app = axum::Router::new()
    .route("/", axum::routing::get(handler))
    .layer(errorgap::tower::ErrorgapLayer::new());
```

For tracing, add the subscriber layer:

```rust
use tracing_subscriber::prelude::*;
tracing_subscriber::registry()
    .with(tracing_subscriber::fmt::layer())
    .with(errorgap::tracing::ErrorgapLayer::default())
    .init();
```

## Trigger a test error

```rust
errorgap::notify(&"Errorgap test error");
errorgap::flush().await;
```

Set `RUST_BACKTRACE=1` so frames are captured.

## Verify

Run the verification curl from [index.md](./index.md), then trigger the test error and confirm the onboarding screen advances.
