Installation
By the end of this guide, your Laravel for Rust app reports its failed requests, jobs and scheduled tasks to Flare, with a trace of each request. Flare connects through a service provider, so your routes, jobs and commands stay as they are.
Building a Rust app without Laravel? Follow the Rust quick start instead.
Install the SDK
You need a Flare account and a project with Laravel (Rust) as its technology. Grab the private API key from your project's settings page.
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-KEYwith 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
Add the flareapp crate with the laravel feature. Like Laravel for Rust itself, it needs Rust 1.99 or newer:
Terminal
cargo add flareapp --features laravel
To show the file and line of each frame, turn on debug info for release builds:
In Cargo.toml:
Terminal
[profile.release]
debug = "limited"
Step 2: Register the Flare service provider
Add the Flare service provider where your app calls Application::configure():
In src/main.rs:
Rust
fn main() -> std::process::ExitCode {
laravel::Application::configure()
.with_providers(|providers| {
providers.add(flareapp::laravel::provider(flareapp::config!()));
})
.run()
}
The provider reports your failed requests, jobs, scheduled tasks and workflows. To report an error that your code handles, call laravel::report(). In the testing environment, the provider does nothing.
Step 3: Connect your project key
Add your project key to your .env file:
If you send traces and logs:
In .env:
Terminal
FLARE_KEY=YOUR-API-KEY
# Sends 10% of traces. Raise it for more detail, lower it to save quota.
FLARE_TRACES_SAMPLE_RATE=0.1
# Sends your info, warning and error log lines.
FLARE_SEND_LOGS=info
If you send traces but no logs:
In .env:
Terminal
FLARE_KEY=YOUR-API-KEY
# Sends 10% of traces. Raise it for more detail, lower it to save quota.
FLARE_TRACES_SAMPLE_RATE=0.1
If you send logs but no traces:
In .env:
Terminal
FLARE_KEY=YOUR-API-KEY
# Sends your info, warning and error log lines.
FLARE_SEND_LOGS=info
If you send no traces and no logs:
In .env:
Terminal
FLARE_KEY=YOUR-API-KEY
For every setup:
Flare uses your APP_ENV as its environment. Set FLARE_ENVIRONMENT to show another one.
For the full stack trace of each error, also set RUST_LIB_BACKTRACE=1. Without it, a report only shows the place where the error started.
Step 4: Verify your setup
Add this route temporarily to your web routes, run your app and open /flare-test. The error should appear in Flare:
In src/routes/web.rs:
Rust
route.get("/flare-test", async || {
Err::<String, _>(laravel::Error::msg("This is an error to test if the integration with Flare works."))
});
Prefer to set it up by hand, or not logged in? Add the crate with the laravel feature. Like Laravel for Rust itself, it needs Rust 1.99 or newer:
Terminal
cargo add flareapp --features laravel
Then add the Flare service provider where your app calls Application::configure():
Rust
fn main() -> std::process::ExitCode {
laravel::Application::configure()
.with_providers(|providers| {
providers.add(flareapp::laravel::provider(flareapp::config!()));
})
.run()
}
Connect your project key
Add your key to .env:
.env
FLARE_KEY=YOUR-PRIVATE-KEY
Flare reads its settings through Laravel, so the variables can come from your environment or from .env. Without FLARE_ENVIRONMENT, Flare uses your APP_ENV. In the testing environment, the provider does nothing.
Check that errors arrive
Add a route that fails:
Rust
route.get("/flare-test", async || {
Err::<String, _>(laravel::Error::msg("My first Flare error"))
});
Run your app, open /flare-test, then open your project in Flare. The error shows up within a few seconds. Remove the route once you've seen it arrive.
Send traces
Tracing stays off until you pick a sample rate:
.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.
Flare gets the spans that Laravel records, and your requests show up under Performance → Routes. Each request also gets a span for each phase: the global middleware, the routing, the middleware of the web or api group, and the response.
A trace follows your request into the jobs it queues and the HTTP calls it makes. Laravel continues an incoming traceparent header, and adds one to outgoing HTTP calls and queued jobs.
Send logs
Log lines stay out of Flare by default, because they count against your log quota. To send them, pick a minimum level. Flare sends that level and everything above it:
.env
FLARE_SEND_LOGS=info
With info, Flare sends your info, warning and error lines, and skips the debug and trace lines. They show up under Logs. The level names are the ones of the tracing crate: error, warn, info, debug and trace. Write warn, not warning.
Without FLARE_SEND_LOGS, Flare still keeps your recent log lines as breadcrumbs, so an error report shows what happened right before it.
What Flare reports
- Failed requests, jobs, scheduled tasks and workflows. A request fails when Laravel answers it with a
5xxstatus. - Errors you report yourself with
laravel::report(). Flare marks these as handled. - Panics that Laravel catches, in requests, jobs and scheduled tasks.
Every report includes the URL, the headers, the client IP address and the user agent of the request. Sensitive headers, like Authorization and Cookie, are redacted.
Laravel doesn't catch a panic in a thread that your app starts itself. To report those too, add #[flareapp::main] to your main function. The provider then uses the Flare client that the attribute started, with the settings of that client.
Settings
The provider reads these variables:
| Variable | What it does |
|---|---|
FLARE_KEY |
The private API key of your project. Without a key, Flare stays off. |
FLARE_ENVIRONMENT |
The environment that Flare shows, like production. Defaults to APP_ENV. |
FLARE_TRACES_SAMPLE_RATE |
The share of traces to send, from 0.0 (none) to 1.0 (all). Defaults to 0.0. |
FLARE_ENDPOINT |
The URL that Flare sends its data to. You only need it to send to another server. |
FLARE_DEBUG |
true prints what Flare does to stderr. |
FLARE_SEND_LOGS |
The minimum level of the log lines that Flare sends, like info. Off by default. |
When a variable has a value that doesn't parse, like FLARE_DEBUG=maybe, Laravel refuses to start and lists the variable.
To change a setting in code, change the flareapp::laravel::Flare section in a with_config callback:
Rust
.with_config(|config, _| {
config.section_mut::<flareapp::laravel::Flare>().traces_sample_rate = Some(0.1);
})
A setting in the section wins over the same setting in the config you pass to the provider. Settings that need code, like a before_send hook, go on that config: flareapp::config!().before_send(...).
Known limits
Laravel for Rust support is in beta. These parts work differently from a plain Rust app, or don't work yet:
- Full stack traces need
RUST_BACKTRACE. Laravel only captures the stack trace of an error whenRUST_BACKTRACE=1orRUST_LIB_BACKTRACE=1is set. Without it, a report has one frame: the place where the error started. A panic report always has one frame, the place of the panic. - Stripped binaries. Flare finds a call of
laravel::report()by its function name. A binary without symbols, like a build withstrip = true, has no names, so every report of that binary counts as not handled. - The
OTEL_*variables no longer apply. The provider replaces the OTLP exporter of Laravel, so Flare gets the spans instead. - No users yet. Reports don't include the logged-in user.
Next steps
- Release builds and debug files and uploading debug files in CI: readable stack traces from release builds.
- Client hooks: change or drop a report before it's sent.