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
downstream [Layer
]s, via [JsonStorage
] and [Span
]'s extensions
;
- [SlackForwardingLayer
], which sends an HTTP POST request (via [tokio
] and [reqwest
]) to a user-defined Slack webhook URL upon event creation.
Configure the dependencies and pull directly from GitHub:
toml
[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" }
```rust use std::time::Duration;
use regex::Regex; use tracing::{info, instrument}; use tracing_subscriber::{layer::SubscriberExt, Registry};
use tracinglayerslack::{EventFilters, SlackLayer};
pub async fn createuser(id: u64) { for i in 0..2 { networkio(i).await; } info!(param = id, "A user was created"); }
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"); createuser(2).await; tokio::time::sleep(Duration::fromsecs(5)).await; createuser(4).await; tokio::time::sleep(Duration::fromsecs(5)).await; create_user(6).await; }
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;
} ```