Expand description
Sends errors, logs and traces from Rust applications to Flare.
§Getting started
// Reads the API key from the `FLARE_KEY` environment variable or `.env` file.
let _flare = flareapp::init(flareapp::config!().environment("production"));
// Your application runs here. When `_flare` is dropped, queued data is sent
// before the process exits.You can also use #[flareapp::main]. The attribute starts the Flare client,
and also reports an error that main returns:
#[flareapp::main(environment = "production")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Your application runs here.
Ok(())
}§Reporting errors
use flareapp::{Level, User};
use serde_json::json;
flareapp::configure_scope(|scope| scope.set_user(User::new("42").email("a@b.c")));
flareapp::glow("cart updated", Level::Info, json!({ "items": 3 }));
if let Err(error) = std::fs::read_to_string("orders.csv") {
flareapp::report_error(&error);
}
flareapp::report_message("Stock low", Level::Warning);When the panic feature is on, the Flare client also reports panics.
Keep the guard in a named variable like _flare. let _ = flareapp::init(…)
drops the guard right away and stops the Flare client.
§How data is sent
The Flare client sends logs and traces as OTLP, the standard format of
OpenTelemetry, encoded as protobuf. Config::otlp_protocol switches to
OTLP/JSON. The worker thread, a background thread, collects the data and sends
the data in batches, so your code never waits for the network. When a request
fails, the worker thread tries the request again up to 3 times, and waits
longer before each new try.
§Features
ureq(default): sends data with theureqHTTP client. Without this feature, pass your ownTransporttoConfig::transport.backtrace(default): adds stack traces to reports. Without this feature, a report has only the line where the app made the report.panic(default): reports panics. Turns onbacktrace.macros(default): adds the#[flareapp::main]attribute.dotenv(default): reads the settings ofConfig::newfrom the.envfile, when the environment does not set them.tracing: sendstracingspans as traces, and events as logs and breadcrumbs. sqlx queries become query spans. See theflareapp::tracingmodule.log: sendslogrecords as logs and breadcrumbs. See theflareapp::logmodule. You need this feature only when your app does not usetracing.tower: adds middleware that gives each request its own scope and root span. See theflareapp::towermodule.axum: turns ontower, and adds the route name (GET /users/{id}) for axum apps. Thetowermiddleware also detects axum without this feature.actix: adds actix-web middleware that gives each request its own scope and root span, and reports server errors. See theflareapp::actixmodule. Turns onbacktrace.reqwest: continues traces in outgoing reqwest calls. See theflareapp::reqwestmodule.sqlx-postgres,sqlx-mysql,sqlx-sqlite: add a sqlx pool whose query spans name the database and show failed queries. See theflareapp::sqlxmodule.anyhow: reportsanyhow::Error. See theflareapp::anyhowmodule. Turns onbacktrace.opentelemetry: sends the spans of the OpenTelemetry SDK, for apps and frameworks that make their spans withtracing-opentelemetry. See theflareapp::opentelemetrymodule.laravel: adds a service provider for Laravel for Rust, which sends the errors, logs and traces of the app. See theflareapp::laravelmodule. Turns ontracingandopentelemetry, and needs Rust 1.99.
Modules§
- actix
- Adds Flare to actix-web apps. See the
flareapp-actixcrate. - anyhow
- Reports
anyhowerrors. See theflareapp-anyhowcrate. - laravel
- Connects Flare to Laravel for Rust. See the
flareapp-laravelcrate. - log
- Sends
logrecords to Flare. See theflareapp-logcrate. - opentelemetry
- Sends the spans of the OpenTelemetry SDK to Flare. See the
flareapp-opentelemetrycrate. - reqwest
- Continues traces in outgoing reqwest calls. See the
flareapp-reqwestcrate. - sqlx
- Sends sqlx queries as query spans, with the database and the errors. See the
flareapp-sqlxcrate. - tower
- Adds Flare to tower servers like axum. See the
flareapp-towercrate. - tracing
- Sends
tracingspans and events to Flare. See theflareapp-tracingcrate.
Macros§
Structs§
- Config
- Settings for the Flare client.
- Entry
Point - What started the work that a report, log or trace belongs to: a web request, a command, or a queued job. Flare requires an entry point, and groups and filters by it.
- Guard
- A handle that keeps the Flare client running.
initreturns the guard. - Report
- One error, panic or message, on its way to Flare.
- Report
Id - The id of one report, a random UUID. Flare calls it the tracking UUID.
- Request
- An HTTP
POSTrequest to Flare, ready to send. - Response
- The parts of an HTTP response that the Flare client needs: the status, the retry time and the body.
- Scope
- The user, context, attributes, entry point, glows and log breadcrumbs that reports include.
- Transport
Error - The error for a request that got no HTTP response, like a connection failure or a timeout.
- User
- The user that was logged in when an error happened.
- With
Scope - A future that runs with its own scope. Create it with
ScopeFutureExt::with_flare_scope.
Enums§
- Level
- How serious a message or glow is. These are the levels Flare knows, the same as the PSR-3 log levels in PHP.
- Otlp
Protocol - How logs and traces are encoded before they are sent. Set it with
Config::otlp_protocol. - Signal
- The kind of data in a request. Each kind goes to its own endpoint.
Traits§
- Reportable
Error - An error that the Flare client can report: an error type that does not borrow
data, or a
dyn Error. - Scope
Future Ext - Gives a future its own scope, so the user, context and breadcrumbs of one
request stay with that request, across every
.await. - Transport
- Sends requests to Flare. Implement this trait to send data with your own HTTP client.
Functions§
- configure_
scope - Changes the current scope.
- flush
- Waits until all queued logs, spans and error reports are sent, or until
timeouthas passed. Returnstruewhen nothing is left to send. - glow
- Adds a glow: a breadcrumb that shows up on the timeline of the next reports.
- init
- Starts the Flare client and returns a guard that keeps the client running.
- report_
error - Reports an error that your code handled.
- report_
error_ with - Reports an error, and lets you change the report before it is sent.
- report_
message - Reports a message, like a log line that needs attention.
- with_
scope - Runs
workwith an extra scope on the current thread, and removes that scope afterwards, also whenworkpanics.
Attribute Macros§
- main
- Starts the Flare client at the start of
main, and keeps the client running untilmainends.