pub struct Client { /* private fields */ }Expand description
Hands telemetry to the worker thread and controls the thread’s lifetime.
The client puts records on a queue. The worker thread takes them off the queue, groups them into batches and sends them to Flare.
Applications use init, which creates the global client. Integrations get
the global client with current.
Implementations§
Source§impl Client
impl Client
Sourcepub fn start(config: Config) -> Result<Self, StartError>
pub fn start(config: Config) -> Result<Self, StartError>
Starts the worker thread and returns a client that sends to it.
With Config::debug on, this function first prints the warnings about
the environment variables and the .env file. The warnings also print when
the client does not start, for example without an API key.
§Errors
Returns a StartError when the Flare client cannot send anything: when
no API key is set, when no transport is set, or when the operating system
does not start the worker thread.
Sourcepub fn send_log<S: Into<Cow<'static, str>>>(&self, target: S, record: LogRecord)
pub fn send_log<S: Into<Cow<'static, str>>>(&self, target: S, record: LogRecord)
Queues a log record for sending. Returns right away.
target is the tracing or log target that wrote the record, like
my_app::billing. It becomes the name of the record’s instrumentation
scope, which Flare shows as the target of the log.
Sourcepub fn send_trace(&self, spans: Vec<Span>)
pub fn send_trace(&self, spans: Vec<Span>)
Queues all finished spans of one trace for sending. Returns right away.
Flare drops a span when its parent is not in the same request, so the spans of a trace always go out together.
Sourcepub fn traces_sample_rate(&self) -> f64
pub fn traces_sample_rate(&self) -> f64
Returns the share of traces to send, from 0.0 (none) to 1.0 (all).
Sourcepub fn set_framework<N: Into<String>>(&self, name: N, version: Option<String>)
pub fn set_framework<N: Into<String>>(&self, name: N, version: Option<String>)
Adds the framework the app runs on to the resource, as
flare.framework.name and flare.framework.version. Flare shows it with
every error, log and trace that is sent after this call.
Web integrations call this when they detect their framework. Only the first
call counts, and a framework from Config::framework wins.
Sourcepub fn censors_client_ips(&self) -> bool
pub fn censors_client_ips(&self) -> bool
Returns true when the IP address of a client must not be sent. See
Config::censor_client_ips.
Sourcepub fn send_report(&self, report: Report) -> Option<ReportId>
pub fn send_report(&self, report: Report) -> Option<ReportId>
Queues an error report for sending. Returns right away.
Adds the current scope first, then runs the before_send hook. Returns the
tracking id. Returns None when the hook dropped the report. Also returns
None when the queue was full or the worker thread had stopped, because
the client then did not queue the report.
Sourcepub fn send_report_and_wait(&self, report: Report) -> Option<ReportId>
pub fn send_report_and_wait(&self, report: Report) -> Option<ReportId>
Queues an error report and waits until it is sent, or until the shutdown timeout has passed. When the queue is full, this function waits for room and does not drop the report.
Returns None when the before_send hook dropped the report, or when the
queue had no room before the timeout.
The panic integration uses this function, because the process can end right after a panic.
Sourcepub fn app_crates(&self) -> &[String]
pub fn app_crates(&self) -> &[String]
Returns the crates whose frames count as application code.
Sourcepub fn flush(&self, timeout: Duration) -> bool
pub fn flush(&self, timeout: Duration) -> bool
Waits until the worker thread has sent everything in the queue, or until
timeout has passed. Returns true when nothing is left to send.
Data that Flare refused, or that still failed after all retries, is dropped
and also counts as done. When the worker thread must wait longer than
timeout before the next retry, for example because of a Retry-After
header, this function returns false right away.