tracing-layer-slack
provides a [Layer
] implementation for sending [tracing
] events to Slack.
[SlackLayer
] sends POST requests via [tokio
] and [reqwest
] to a Slack Webhook URL for each new tracing event. The format of the text
field is statically defined.
This layer also looks for an optional [JsonStorageLayer
] [extension
](https://docs.rs/tracing-subscriber/0.2.5/tracing_subscriber/registry/struct.ExtensionsMut.html) on the parent [span
] of each event. This extension may contain additional contextual information for the parent span of an event, which is included into the Slack message.
Configure the dependencies and pull directly from GitHub:
toml
[dependencies]
tokio = "1.0"
tracing = "0.1"
tracing-futures = "0.2"
tracing-layer-slack = "0.3"
```rust use regex::Regex; use tracing::{info, warn, instrument}; use tracing_subscriber::{layer::SubscriberExt, Registry};
use tracinglayerslack::{EventFilters, SlackLayer};
pub async fn createuser(id: u64) { networkio(id).await; info!(param = id, "A user was created"); }
pub async fn networkio(id: u64) { warn!(userid = id, "had to retry the request once"); }
pub async fn controller() { info!("Orphan event without a parent span"); tokio::join!(createuser(2), createuser(4), create_user(6)); }
async fn main() { // Only show events from where this example code is the target. let targettofilter: EventFilters = Regex::new("simple").unwrap().into();
// Initialize the layer and an async background task for sending our Slack messages.
let (slack_layer, background_worker) = SlackLayer::builder(target_to_filter).build();
// Initialize the global default subscriber for tracing events.
let subscriber = Registry::default().with(slack_layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
// Perform our application code that needs tracing and Slack messages.
controller().await;
// Waits for all Slack messages to be sent before exiting.
background_worker.shutdown().await;
} ```