Crate tracing_layer_slack[−][src]
Expand description
tracing-layer-slack
tracing-layer-slack
provides a Layer
implementation based on top of a tracing
Subscriber
and tracing-bunyan-formatter
’s JsonStorageLayer
:
JsonStorageLayer
, to attach contextual information to spans for ease of consumption by downstreamLayer
s, viaJsonStorage
andSpan
’sextensions
;SlackForwardingLayer
, which sends an HTTP POST request (viatokio
andreqwest
) to a user-defined Slack webhook URL upon event creation.
Installation
Configure the dependencies and pull directly from GitHub:
[dependencies] tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-futures = "0.2" tracing-bunyan-formatter = { version = "0.2", default-features = false } tracing-layer-slack = { git = "https://github.com/seanpianka/tracing-layer-slack", branch = "master" }
Examples
Simple
use std::time::Duration; use regex::Regex; use tracing::{info, instrument}; use tracing_subscriber::{layer::SubscriberExt, Registry}; use tracing_layer_slack::{EventFilters, SlackLayer}; #[instrument] pub async fn create_user(id: u64) { for i in 0..2 { network_io(i).await; } info!(param = id, "A user was created"); } #[instrument] pub async fn network_io(id: u64) { info!(id, "We did our network I/O thing"); } pub async fn controller() { info!("Orphan event without a parent span"); create_user(2).await; tokio::time::sleep(Duration::from_secs(5)).await; create_user(4).await; tokio::time::sleep(Duration::from_secs(5)).await; create_user(6).await; } #[tokio::main] async fn main() { // Only show events from where this example code is the target. let target_to_filter: 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; }
Structs
EventFilters describes two optional lists of regular expressions used to filter events.
This worker manages a background async task that schedules the network requests to send traces to the Slack on the running tokio runtime.
Configuration describing how to forward tracing events to Slack.
Layer for forwarding tracing events to Slack.
A builder for creating a Slack layer.