# Quick start


By the end of this guide, your Rust app reports panics and errors to Flare, with stack traces you can read in release builds. The optional steps after that hook up your web framework and send your logs and traces.

Everything goes through one crate, `flareapp`. It handles errors, logs and traces, works in both sync and async code, and needs Rust 1.94 or newer. The SDK sends its data from a background thread, so a slow network never holds up your app.

## Install the SDK

You need a Flare account and a project with Rust as its technology. Grab the private API key from your project's settings page. Error reports work with either key, but logs, traces and debug file uploads only accept the private one, so it's easiest to use that key everywhere.

The interactive guide below is the fastest way to get started. When you're logged in, pick one of your projects and the guide fills in its key for you. You can also copy the install prompt and let an AI coding assistant do the work.

> This guide covers every supported setup. Follow only the steps that match your project: conditional instructions start with a bold "If ..." line describing when they apply. Steps without such a line always apply.
> Replace `YOUR-API-KEY` with the project's API key. You can find it in the project settings on https://flareapp.io.

## Step 1: Install the Flare client using Cargo

**If your app uses Axum and you add host details:**

```shell
cargo add flareapp --features tracing,axum,host-details

# Only if your app doesn't use tracing yet:
cargo add tracing tracing-subscriber
```

**If your app uses Axum and you do not add host details:**

```shell
cargo add flareapp --features tracing,axum

# Only if your app doesn't use tracing yet:
cargo add tracing tracing-subscriber
```

**If your app uses Actix Web and you add host details:**

```shell
cargo add flareapp --features tracing,actix,host-details

# Only if your app doesn't use tracing yet:
cargo add tracing tracing-subscriber
```

**If your app uses Actix Web and you do not add host details:**

```shell
cargo add flareapp --features tracing,actix

# Only if your app doesn't use tracing yet:
cargo add tracing tracing-subscriber
```

**If your app uses no web framework and you add host details:**

```shell
cargo add flareapp --features tracing,host-details

# Only if your app doesn't use tracing yet:
cargo add tracing tracing-subscriber
```

**If your app uses no web framework and you do not add host details:**

```shell
cargo add flareapp --features tracing

# Only if your app doesn't use tracing yet:
cargo add tracing tracing-subscriber
```

**For every setup:**

To show the file and line of each frame, turn on debug info for release builds:

In `Cargo.toml`:

```shell
[profile.release]
debug = "limited"
```

## Step 2: Register Flare & configure

Add `#[flareapp::main]` to your `main` function, and add the Flare layer to your `tracing` subscriber:

**If your app does not use Actix Web:**

In `src/main.rs`:

```rust
use tracing_subscriber::{filter::LevelFilter, prelude::*};

// Sends 10% of traces. Raise it for more detail, lower it to save quota.
#[flareapp::main(traces_sample_rate = 0.1)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tracing_subscriber::registry()
        .with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
        .with(flareapp::tracing::layer())
        .init();

    // Run your app here.

    Ok(())
}
```

**If your app uses Actix Web:**

In `src/main.rs`:

```rust
use tracing_subscriber::{filter::LevelFilter, prelude::*};

// Sends 10% of traces. Raise it for more detail, lower it to save quota.
#[flareapp::main(traces_sample_rate = 0.1)]
#[actix_web::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tracing_subscriber::registry()
        .with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
        .with(flareapp::tracing::layer())
        .init();

    // Run your app here.

    Ok(())
}
```

**For every setup:**

If you do not set a sample rate, the client sends no traces.

If your app already calls `tracing_subscriber::registry()`, only add the `.with(flareapp::tracing::layer())` line to it.

To send logs to Flare, call `send_logs` on the Flare layer:

In `src/main.rs`:

```rust
tracing_subscriber::registry()
    .with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
    .with(flareapp::tracing::layer().send_logs(tracing::Level::INFO))
    .init();
```

**If your app uses Axum:**

Add the Flare layer after your routes, and serve the router with connect info:

In `src/main.rs`:

```rust
use std::net::SocketAddr;

use axum::{routing::get, Router};

let app = Router::new()
    .route("/users/{id}", get(show_user))
    .layer(flareapp::tower::layer());

let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app.into_make_service_with_connect_info::<SocketAddr>()).await?;
```

**If your app uses Actix Web:**

Wrap your app in the Flare middleware:

In `src/main.rs`:

```rust
use actix_web::{App, HttpServer};

HttpServer::new(|| {
    App::new()
        .wrap(flareapp::actix::middleware())
        .service(show_user)
})
```

**If your app uses SQLx:**

SQLx needs no extra code, unless you turned off query logging. Turn it back on:

In `src/main.rs`:

```rust
use sqlx::{postgres::PgConnectOptions, ConnectOptions};

let options = database_url
    .parse::<PgConnectOptions>()?
    .log_statements(log::LevelFilter::Debug);
```

**For every setup:**

To report errors that your code handles, see [reporting errors](https://flareapp.io/docs/rust/errors/reporting-errors#reporting-an-error-you-handled).

## Step 3: Connect your project key

Add your project key to your environment, or to a `.env` file in the folder your app runs from:

In `.env`:

```shell
FLARE_KEY=YOUR-API-KEY
FLARE_ENVIRONMENT=production
```

## Step 4: Verify your setup

Add this line temporarily to `main`, after the Flare setup, and run your app. The panic should appear in Flare:

In `src/main.rs`:

```rust
panic!("This is a panic to test if the integration with Flare works.");
```

Prefer to set it up by hand, or not logged in? Add the crate:

```bash
cargo add flareapp
```

The default features cover panics and errors with a stack trace. Logs, traces and web frameworks each have their own feature, which you'll turn on later in this guide.

Then add `#[flareapp::main]` to your `main` function:

```rust
// src/main.rs
#[flareapp::main]
fn main() {
    // Your app runs here.
}
```

The attribute starts Flare before your code runs, and sends whatever is still queued when `main` returns. If `main` returns an error, Flare reports that too. It works on an async `main` as well, next to `#[tokio::main]` or `#[actix_web::main]`:

```rust
// src/main.rs
#[flareapp::main]
#[tokio::main]
async fn main() {
    // Your app runs here.
}
```

From this point on, every panic gets reported, on every thread.

### Connect your project key

Flare reads its settings from environment variables, so the key never has to live in your code:

```dotenv
# .env
FLARE_KEY=YOUR-API-KEY
FLARE_ENVIRONMENT=production
```

Set these in the environment of your app, or in a `.env` file in the folder your app runs in. When a variable is in both places, the environment wins. See [the `.env` file](/docs/rust/reference/configuration#the-codeenvcode-file) for the details.

Without `FLARE_KEY`, Flare is switched off and every Flare call quietly does nothing. That's handy on your own machine: leave the key out locally, and you won't burn through your quota while you work.

## Check that errors arrive

Add a test panic somewhere your code runs, for example at the start of `main`:

```rust
panic!("My first Flare error");
```

Run your app, then open your project in Flare. The error shows up within a few seconds as a `Panic`, with its message and a stack trace. Remove the test panic once you've seen it arrive.

Nothing there? See [nothing arrives in Flare](/docs/rust/getting-started/troubleshooting#nothing-arrives-in-flare).

## Keep stack traces readable in release builds

The SDK resolves stack traces inside your app, which means your release binary needs debug info. Cargo leaves it out of release builds by default, so turn it on:

```toml
# Cargo.toml
[profile.release]
debug = "limited"
```

Without it, you still get function names, but no files or line numbers. Debug info makes the binary bigger, not slower: the compiler generates the same machine code either way.

Rather ship a small, stripped binary? Then upload its debug files to Flare during your build, and Flare resolves the stack traces when the reports come in. See [release builds and debug files](/docs/rust/errors/release-builds-and-debug-files) for how that works, and [uploading debug files in CI](/docs/rust/errors/uploading-debug-files-in-ci) for ready-made Linux, macOS and Windows pipelines.

## Add your web framework

You've got error reporting working. The next steps are optional, and nothing below is needed to get errors into Flare.

If your app serves HTTP with axum or Actix Web, add the Flare middleware. Without it, an error report doesn't know which request it came from. With it, you get:

- **The request on every error**: the method, the URL, the route, the user agent and the headers. Flare censors sensitive headers like `Authorization` and `Cookie` before the report leaves your app.
- **Errors and logs filed under their route**, like `GET /users/{id}`, so you see right away which endpoint breaks.
- **A separate scope for each request**: the user, context and breadcrumbs you add in one request never end up on the error of another.
- **A trace for every request**, once you turn on tracing in the [next step](#send-logs-and-traces). Flare then shows how fast each route is.

Turn on the feature for your framework, and add the middleware:

```bash tab=axum
cargo add flareapp --features axum
```

```bash tab=actix-web
cargo add flareapp --features actix
```

```rust tab=axum
// src/main.rs
use std::net::SocketAddr;

use axum::{extract::Path, routing::get, Router};

async fn show_user(Path(id): Path<u64>) -> String {
    format!("User {id}")
}

#[flareapp::main]
#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/users/{id}", get(show_user))
        .layer(flareapp::tower::layer());

    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap();

    axum::serve(
        listener,
        app.into_make_service_with_connect_info::<SocketAddr>(),
    )
    .await
    .unwrap();
}
```

```rust tab=actix-web
// src/main.rs
use actix_web::{web, App, HttpServer};

async fn show_user(id: web::Path<u64>) -> String {
    format!("User {}", id.into_inner())
}

#[flareapp::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .wrap(flareapp::actix::middleware())
            .route("/users/{id}", web::get().to(show_user))
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}
```

To check it, send a test message from one of your handlers, and open that route in your browser:

```rust
flareapp::report_message("Hello from a request", flareapp::Level::Info);
```

The message shows up in Flare with the request it came from: the method, the URL and the route.

## Send logs and traces

Logs and traces go through the `tracing` crate. Turn on the `tracing` feature and add the Flare layer to your subscriber:

```bash
cargo add flareapp --features tracing
cargo add tracing tracing-subscriber
```

```rust
// src/main.rs
use tracing_subscriber::{filter::LevelFilter, prelude::*};

#[flareapp::main]
#[tokio::main]
async fn main() {
    tracing_subscriber::registry()
        .with(tracing_subscriber::fmt::layer().with_filter(LevelFilter::INFO))
        .with(flareapp::tracing::layer().send_logs(tracing::Level::INFO))
        .init();

    // Your app runs here.
}
```

`send_logs` sends every event at INFO or above to Flare as a log line. Leave it out if you only care about errors: the layer still keeps your recent log lines as breadcrumbs, so an error report shows what happened right before it.

Keep the `LevelFilter` on the `fmt` layer, like above. A filter on the whole subscriber hides events from Flare too. See [where your filters go](/docs/rust/logs/introduction#where-your-filters-go).

Tracing stays off until you pick a sample rate:

```dotenv
# .env
FLARE_TRACES_SAMPLE_RATE=0.1
```

This sends one trace out of every ten. Set it to `1.0` while you're setting things up, so you see every trace, and lower it once real traffic comes in.

With the middleware from the previous step, every request now becomes a trace, grouped on its route like `GET /users/{id}`. If your app uses SQLx, every query shows up as a span in that trace, with no extra code.

To check it, send a few requests to your app. After a few seconds, they show up under Performance → Routes in your project, and your log lines show up under Logs.

## Next steps

- [Reporting errors](/docs/rust/errors/reporting-errors): report handled errors, `anyhow` errors and messages yourself.
- [Client hooks](/docs/rust/errors/client-hooks): change or drop a report before it's sent.
- [Release builds and debug files](/docs/rust/errors/release-builds-and-debug-files) and [uploading debug files in CI](/docs/rust/errors/uploading-debug-files-in-ci): readable stack traces from stripped binaries.
- [Adding custom context](/docs/rust/data-collection/adding-custom-context), [identifying users](/docs/rust/data-collection/identifying-users) and [adding glows](/docs/rust/data-collection/adding-glows).
- [Scopes](/docs/rust/data-collection/scopes): keep the data of one request or job away from the others.
- [Logs](/docs/rust/logs/introduction): the `tracing` and `log` integrations.
- [Tracing](/docs/rust/tracing/introduction) and [instrumenting your code](/docs/rust/tracing/instrumenting-your-code): what Flare shows, and how to add your own functions, jobs and outgoing HTTP calls.
- [Configuration](/docs/rust/reference/configuration): every environment variable, attribute argument and Cargo feature.
- [Troubleshooting](/docs/rust/getting-started/troubleshooting): what to check when something doesn't show up.
