pub struct Config { /* private fields */ }Expand description
Settings for the Flare client.
Applications usually start with the flareapp::config! macro, which also sets
the name and version of the application.
§Examples
let config = flareapp_core::Config::new()
.api_key("your-api-key")
.environment("production");Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a config with the default settings, filled in from these
environment variables, or from the .env file, when they are set:
| Variable | Setting |
|---|---|
FLARE_KEY | Config::api_key |
FLARE_ENVIRONMENT | Config::environment |
FLARE_TRACES_SAMPLE_RATE | Config::traces_sample_rate, like 0.1 |
FLARE_ENDPOINT | Config::endpoint |
FLARE_DEBUG | Config::debug: true or 1 |
OTEL_EXPORTER_OTLP_PROTOCOL | Config::otlp_protocol: http/protobuf or http/json |
The .env file is the file in the current folder. The Flare client does
not search parent folders. The Flare client only reads the file. The Flare
client does not change the environment of your app. Reading the .env file
needs the dotenv feature of the flareapp crate, which is on by default.
An environment variable wins over the same variable in the .env file.
Settings you make in code afterwards win over both.
Sourcepub fn api_key<S: Into<String>>(self, api_key: S) -> Self
pub fn api_key<S: Into<String>>(self, api_key: S) -> Self
Sets the API key of your Flare project. An empty key disables the Flare client. Spaces and line breaks around the key are removed.
Logs and traces need the private API key of your project.
Sourcepub fn endpoint<S: Into<String>>(self, endpoint: S) -> Self
pub fn endpoint<S: Into<String>>(self, endpoint: S) -> Self
Sets the URL that data is sent to. The default is https://ingress.flareapp.io.
Logs and traces can go to any server that accepts OTLP over HTTP, for
example a local OpenTelemetry Collector on http://localhost:4318. The
config removes spaces and line breaks around the URL. The config also removes a
slash at the end. The config ignores a blank URL, so the endpoint stays
the same.
Sourcepub fn otlp_protocol(self, protocol: OtlpProtocol) -> Self
pub fn otlp_protocol(self, protocol: OtlpProtocol) -> Self
Sets how logs and traces are encoded. The default is
OtlpProtocol::HttpProtobuf.
Use OtlpProtocol::HttpJson when you want to read the requests, or for a
server that only accepts OTLP/JSON. Error reports are always sent as JSON.
Sourcepub fn service_name<S: Into<String>>(self, name: S) -> Self
pub fn service_name<S: Into<String>>(self, name: S) -> Self
Sets the name of your application, sent as service.name.
Without a name, Flare receives unknown_service:<name of the executable>.
Sourcepub fn service_version<S: Into<String>>(self, version: S) -> Self
pub fn service_version<S: Into<String>>(self, version: S) -> Self
Sets the version of your application, sent as service.version.
Sourcepub fn git_hash<S: Into<String>>(self, hash: S) -> Self
pub fn git_hash<S: Into<String>>(self, hash: S) -> Self
Sets the git commit of the code that runs, sent as git.hash. Flare shows
the first 7 characters as the version of your application. A blank hash
removes the hash.
flareapp::config! sets the hash when you build the app with
FLARE_GIT_HASH, or on a CI that gives the commit, like GitHub Actions.
Without a hash, the Flare client runs git in the
Config::application_path when it starts, if that folder exists. The
Flare client then also sends the branch and the newest tag.
Sourcepub fn environment<S: Into<String>>(self, environment: S) -> Self
pub fn environment<S: Into<String>>(self, environment: S) -> Self
Sets the environment your application runs in, like production or staging.
The config removes spaces and line breaks around the name. A blank name
removes the environment.
Sourcepub fn debug(self, debug: bool) -> Self
pub fn debug(self, debug: bool) -> Self
Prints what the Flare client does to stderr, like sent requests and errors. Turn this on while you set up the Flare client.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets the longest time that one HTTP request to Flare can take. The default is 10 seconds.
Only the default HTTP client uses this setting. A transport that you set with
Config::transport uses its own timeouts.
Sourcepub fn shutdown_timeout(self, timeout: Duration) -> Self
pub fn shutdown_timeout(self, timeout: Duration) -> Self
Sets how long the Guard waits for queued data to be sent
when it is dropped. The default is 2 seconds.
Sourcepub fn queue_capacity(self, capacity: usize) -> Self
pub fn queue_capacity(self, capacity: usize) -> Self
Sets how many records can wait in the queue. The default is 1024. A value of 0 becomes 1.
When the queue is full, new records are dropped, so your application never waits for Flare.
The worker thread also keeps at most this many records of each kind while they wait to be sent. When that limit is reached, the oldest record is dropped.
Sourcepub fn batch_size(self, size: usize) -> Self
pub fn batch_size(self, size: usize) -> Self
Sets the maximum number of log records, or of traces, sent in one request. The default is 100. A value of 0 becomes 1.
A trace is never split over two requests, so one request can hold more spans than this number. Error reports are always sent one per request.
Sourcepub fn batch_interval(self, interval: Duration) -> Self
pub fn batch_interval(self, interval: Duration) -> Self
Sets how long logs and spans wait before they are sent, so they can be sent together in one request. The default is 5 seconds.
Sourcepub fn transport<T: Transport>(self, transport: T) -> Self
pub fn transport<T: Transport>(self, transport: T) -> Self
Replaces the HTTP client that sends data to Flare.
Use this to send data with your own HTTP client, or to capture requests in
tests. See Transport.
Sourcepub fn before_send<F>(self, hook: F) -> Self
pub fn before_send<F>(self, hook: F) -> Self
Runs hook before each report is sent. Return false to drop the report.
Use this hook to remove sensitive data, or to skip errors that you do not want in Flare.
§Examples
let config = flareapp_core::Config::new().before_send(|report| {
report.exception_class() != "my_app::NotFound"
});Sourcepub fn app_crate<S: Into<String>>(self, name: S) -> Self
pub fn app_crate<S: Into<String>>(self, name: S) -> Self
Marks the frames of a crate as application code. Write the crate name as in
your Cargo.toml, like my-billing, or with underscores, like
my_billing. Both spellings work. The macro flareapp::config! adds your
own crate.
Sourcepub fn application_path<S: Into<String>>(self, path: S) -> Self
pub fn application_path<S: Into<String>>(self, path: S) -> Self
Sets the root folder of your application. Flare uses it to show shorter file
paths. flareapp::config! sets it to the folder of your Cargo.toml.
Sourcepub fn workspace_root<S: Into<String>>(self, path: S) -> Self
pub fn workspace_root<S: Into<String>>(self, path: S) -> Self
Sets the root folder of your Cargo workspace, or the folder of your
Cargo.toml when there is no workspace. flareapp::config! finds it.
Rust gives the file of a report location, like the line of a panic,
relative to this folder, like crates/app/src/main.rs. The Flare client puts
this folder in front of that path, so the path matches the rest of the stack
trace. When you build with --remap-path-prefix, set workspace_root to the
new prefix.
Sourcepub fn framework<N: Into<String>>(
self,
name: N,
version: Option<String>,
) -> Self
pub fn framework<N: Into<String>>( self, name: N, version: Option<String>, ) -> Self
Sets the framework the application is built on, sent as
flare.framework.name and flare.framework.version. Framework
integrations set this value. Use a lowercase name.
Sourcepub fn traces_sample_rate(self, rate: f64) -> Self
pub fn traces_sample_rate(self, rate: f64) -> Self
Turns tracing on and sets the share of traces to send: from 0.0 (none, the
default) to 1.0 (all). Flare’s PHP client uses 0.1. A value below 0.0
becomes 0.0, a value above 1.0 becomes 1.0, and NaN becomes 0.0.
The Flare client decides once per trace, at the first span of the trace.
When an incoming request has a traceparent header, the decision in that
header wins.
Sourcepub fn censor_client_ips(self, censor: bool) -> Self
pub fn censor_client_ips(self, censor: bool) -> Self
Stops sending the IP address of the client that made a request, as
client.address. By default, the web integrations send it, like Flare’s PHP
client.
Sourcepub fn default_transport<T, F>(self, make: F) -> Self
pub fn default_transport<T, F>(self, make: F) -> Self
Sets the transport that make creates, but only when no transport is set.
make gets the request timeout from Config::timeout. The flareapp
crate uses this to set its default HTTP client.