Configuration
Flare picks up its settings from three places, and a later one wins over an earlier one:
- The
.envfile of your app. - The environment variables of the process.
- The settings you make in code.
Most apps only need FLARE_KEY and FLARE_ENVIRONMENT, and keep everything else at its default.
Environment variables
| Variable | Description |
|---|---|
FLARE_KEY |
The private API key of your project. Without it, Flare is disabled and every Flare call does nothing. |
FLARE_ENVIRONMENT |
The environment your app runs in, like production or staging. |
FLARE_TRACES_SAMPLE_RATE |
The share of traces to send, from 0.0 to 1.0. Tracing is off without it. |
FLARE_DEBUG |
true or 1 prints what Flare does to stderr: a line for every request it sends, with the status code it gets back, and the answer when a request fails. Handy while you set things up. |
FLARE_ENDPOINT |
The URL Flare sends data to. Defaults to https://ingress.flareapp.io. You only need it to send to another server, like a local OpenTelemetry Collector on http://localhost:4318. A Collector only takes the logs and traces: error reports go to /v1/errors, which it doesn't know. |
OTEL_EXPORTER_OTLP_PROTOCOL |
Flare sends logs and traces as OTLP protobuf. Set it to http/json for OTLP JSON, for example for a server at FLARE_ENDPOINT that only reads JSON. Error reports are always JSON. |
FLARE_GIT_HASH is a bit different: it's read while your app compiles, not while it runs. See application info.
The .env file
Flare reads the same variables from a .env file. It only looks in the folder your app runs in, not in parent folders. You don't need dotenvy for Flare.
Flare only reads the file. It doesn't add its values to the environment of your app, so if your own code needs DATABASE_URL from the same file, keep loading it for that. Flare stops reading the file at the first line it can't parse, and with FLARE_DEBUG=true it tells you when that happens.
To skip the .env file entirely, turn off the dotenv feature. It's a default feature, so you turn off the defaults and add the others back:
Terminal
cargo add flareapp --no-default-features --features ureq,backtrace,panic,macros
Attribute arguments
#[flareapp::main] takes a few settings directly:
Rust
#[flareapp::main(environment = "production", traces_sample_rate = 0.1, debug = true)]
fn main() {}
| Argument | Description |
|---|---|
environment = "..." |
Same as FLARE_ENVIRONMENT. |
traces_sample_rate = 0.1 |
Same as FLARE_TRACES_SAMPLE_RATE. |
debug = true |
Same as FLARE_DEBUG. |
config = my_config |
A function fn my_config() -> flareapp::Config that returns the config to start from. Use it for every setting below. |
crate = "path" |
The path to the flareapp crate, if you renamed it in your Cargo.toml. |
The other arguments are applied on top of the config that config returns. There's no argument for the API key, on purpose: keep it out of your code and in the environment.
Settings in code
For everything else, write a function that builds a Config, and pass it to the attribute:
Rust
use std::time::Duration;
fn flare_config() -> flareapp::Config {
flareapp::config!()
.environment("production")
.shutdown_timeout(Duration::from_secs(5))
.before_send(|report| report.exception_class() != "my_app::NotFound")
}
#[flareapp::main(config = flare_config)]
fn main() {}
Always start from flareapp::config!(). It reads the environment variables and the .env file just like Config::new(), and also fills in the name and version of your crate, the git commit and the folder of your project.
| Method | Default | Description |
|---|---|---|
api_key(key) |
FLARE_KEY |
The API key of your project. An empty key disables Flare. |
environment(name) |
FLARE_ENVIRONMENT |
The environment your app runs in. |
traces_sample_rate(rate) |
FLARE_TRACES_SAMPLE_RATE, else 0.0 |
The share of traces to send. 0.0 turns tracing off. |
debug(on) |
FLARE_DEBUG, else false |
Prints what Flare does to stderr. |
endpoint(url) |
FLARE_ENDPOINT, else https://ingress.flareapp.io |
The URL Flare sends data to. |
otlp_protocol(protocol) |
OTEL_EXPORTER_OTLP_PROTOCOL, else OtlpProtocol::HttpProtobuf |
How logs and traces are encoded. OtlpProtocol::HttpJson sends OTLP JSON. |
before_send(hook) |
none | Changes or drops reports before they're sent. See client hooks. |
censor_client_ips(on) |
false |
Leaves the IP address of the client out of requests. |
service_name(name) |
your crate name | The name of your app. |
service_version(version) |
your crate version | The version of your app. |
git_hash(hash) |
the commit from your CI | The git commit your app was built from. A blank hash removes it, but when your project folder exists on the machine, Flare then reads the commit with git when it starts. |
timeout(duration) |
10 seconds | How long one request to Flare may take. |
shutdown_timeout(duration) |
2 seconds | How long Flare waits for queued data to go out when your program ends. |
queue_capacity(count) |
1024 | How many records can wait to be sent. When the queue is full, new records are dropped, so your app never waits for Flare. |
batch_size(count) |
100 | The most log lines, or traces, sent in one request. A trace is never split over two requests. |
batch_interval(duration) |
5 seconds | How long logs and spans wait, so they can go out together in one request. |
app_crate(name) |
your crate | Marks the frames of another crate as your own code. Use the crate name, like my-shared-lib or my_shared_lib. Handy in a workspace. |
application_path(path) |
the folder of your Cargo.toml |
The root folder of your app, used to show shorter file paths. |
workspace_root(path) |
your Cargo workspace | The root folder of your workspace. Set it to the new prefix when you build with --remap-path-prefix. |
transport(transport) |
the built-in HTTP client | Sends data with your own HTTP client, or captures it in tests. See the Transport trait on docs.rs. |
Without the attribute
If you can't use #[flareapp::main], for example because main lives in a framework you don't control, start Flare yourself and keep the guard it returns:
src/main.rs
fn main() {
let _flare = flareapp::init(flareapp::config!());
// Your app runs here.
}
The guard keeps Flare running. When it's dropped, Flare sends what's still queued, waits at most the shutdown_timeout, and stops. That's why it needs a name like _flare: let _ = flareapp::init(...) drops the guard on the same line, and Flare stops before your app even starts.
Without the attribute, an error that main returns isn't reported for you. Report it yourself with report_error before you return it.
Cargo features
The flareapp crate keeps its integrations behind features, so you only compile what you use.
| Feature | Default | What it adds |
|---|---|---|
ureq |
yes | The built-in HTTP client that sends data to Flare. Without it, set your own with Config::transport. |
backtrace |
yes | Stack traces on error reports. |
panic |
yes | Reports panics. Turns on backtrace. |
macros |
yes | The #[flareapp::main] attribute. |
dotenv |
yes | Reads settings from the .env file. |
tracing |
no | The tracing layer for logs, breadcrumbs and traces. See logs and tracing. |
log |
no | The integration for the log crate. See logs. |
tower |
no | The request middleware for servers built on tower. |
axum |
no | The tower middleware, plus the route names of axum. |
actix |
no | The request middleware for Actix Web 4.17 or newer. |
reqwest |
no | Trace propagation for outgoing reqwest calls, for reqwest 0.13 and reqwest-middleware 0.5. Turns on tracing. See outgoing HTTP calls. |
sqlx-postgres, sqlx-mysql, sqlx-sqlite |
no | flareapp::sqlx::Pool, a SQLx pool whose query spans name the database and show failed queries. Turns on tracing. See the Flare SQLx pool. |
anyhow |
no | Reporting anyhow::Error. See anyhow errors. |
host-details |
no | The IP address of the host and the name and version of its operating system. See host details. |
API reference
The full API, with every type and method, is on docs.rs/flareapp.