pub trait Subscriber: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn deliver(
&self,
report: &Report,
vars: &dyn Fn(&str) -> Option<String>,
) -> Option<Delivery>;
}Expand description
An error-reporting service (Rails’ error subscribers): turns a Report into the request to send.
vars looks up a Worker variable or secret by name (the service’s key).
Return None to send nothing, e.g. when the key is not set. Ocre sends
the Delivery with fetch and logs a failed send; it never retries.
§Examples
use ocre::errors::{Delivery, Report, Subscriber};
/// Posts each error to a webhook (a chat channel, an incident tool...).
struct Webhook;
impl Subscriber for Webhook {
fn name(&self) -> &'static str {
"webhook"
}
fn deliver(&self, report: &Report, vars: &dyn Fn(&str) -> Option<String>) -> Option<Delivery> {
let url = vars("ERRORS_WEBHOOK_URL")?;
let body = serde_json::json!({ "text": format!("{}: {}", report.source, report.message) }).to_string();
Some(Delivery { url, headers: vec![("content-type".into(), "application/json".into())], body })
}
}
ocre::errors::subscribe(Webhook);Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
A short name, for Options::except and failure logs: sentry.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".