Struct tracing_layer_discord::BackgroundWorker
source · pub struct BackgroundWorker { /* private fields */ }
Expand description
This worker manages a background async task that schedules the network requests to send traces to the Discord on the running tokio runtime.
Ensure to invoke .startup()
before, and .teardown()
after, your application code runs. This
is required to ensure proper initialization and shutdown.
tracing-layer-discord
synchronously generates payloads to send to the Discord API using the
tracing events from the global subscriber. However, all network requests are offloaded onto
an unbuffered channel and processed by a provided future acting as an asynchronous worker.
Implementations§
source§impl BackgroundWorker
impl BackgroundWorker
sourcepub async fn shutdown(self)
pub async fn shutdown(self)
Initiate the worker’s shutdown sequence.
Without invoking.teardown()
, your application may exit before all Discord messages can be
sent.
Examples found in repository?
More examples
examples/exclude_fields_from_messages.rs (line 31)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
async fn main() {
let targets_to_filter: EventFilters = Regex::new("exclude_fields_from_messages").unwrap().into();
let fields_to_exclude = vec![
Regex::new(".*token.*").unwrap(),
Regex::new(".*password.*").unwrap(),
Regex::new("command").unwrap(),
];
let (discord_layer, background_worker) = DiscordLayer::builder("test-app".to_string(), targets_to_filter)
.field_exclusion_filters(fields_to_exclude)
.build();
let subscriber = Registry::default().with(discord_layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
handler().await;
background_worker.shutdown().await;
}
Trait Implementations§
source§impl Clone for BackgroundWorker
impl Clone for BackgroundWorker
source§fn clone(&self) -> BackgroundWorker
fn clone(&self) -> BackgroundWorker
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for BackgroundWorker
impl !RefUnwindSafe for BackgroundWorker
impl Send for BackgroundWorker
impl Sync for BackgroundWorker
impl Unpin for BackgroundWorker
impl !UnwindSafe for BackgroundWorker
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more