#tracing-layer #webhook #tracing #logging-tracing #async #filter #layer

tracing-layer-core

Send filtered tracing events to a webhook endpoint

4 releases (2 breaking)

0.3.0 Jul 3, 2024
0.2.1 Apr 21, 2024
0.2.0 Apr 15, 2024
0.1.0 Apr 15, 2024

#683 in Debugging

Download history 24/week @ 2024-07-22 19/week @ 2024-07-29 15/week @ 2024-08-26 105/week @ 2024-09-09 86/week @ 2024-09-16 74/week @ 2024-09-23 92/week @ 2024-09-30 99/week @ 2024-10-07 14/week @ 2024-10-14 48/week @ 2024-10-21 6/week @ 2024-10-28 23/week @ 2024-11-04

103 downloads per month
Used in 2 crates

Apache-2.0

32KB
433 lines

tracing-layer-slack-discord

This repository contains Layer implementations for sending tracing events to Slack and Discord.

tracing-layer-slack tracing-layer-slack on crates.io Docs

tracing-layer-discord tracing-layer-discord on crates.io Docs

Synopsis

DiscordLayer and SlackLayer send POST requests via tokio and reqwest to a Discord Webhook URL and Slack Webhook URL for each new tracing event, depending on the user-supplied event filtering rules. The format of the embedded message is statically defined.

This layer also looks for an optional JsonStorageLayer extension 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 Discord message.

Features

  • Send trace logs to Slack and Discord channels.
  • Configurable to suit your needs.
  • Easy to integrate with existing Rust applications.

Usage

Add the following to your Cargo.toml:

[dependencies]
tracing-layer-slack = "0"
tracing-layer-discord = "0"

Then, in your application:

use regex::Regex;
use tracing::{info, instrument, warn};
use tracing_subscriber::{layer::SubscriberExt, Registry};

use tracing_layer_slack::{EventFilters, SlackLayer};
use tracing_layer_discord::{EventFilters, DiscordLayer};

#[instrument]
pub async fn network_io(id: u64) {
    warn!(user_id = id, "had to retry the request once");
}

#[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();

    let app_name = "test-app".to_string();
    let (slack_layer, slack_worker) = SlackLayer::builder(app_name.clone(), target_to_filter.clone()).build();
    let (discord_layer, discord_worker) = DiscordLayer::builder(app_name, target_to_filter).build();
    let subscriber = Registry::default().with(slack_layer);
    tracing::subscriber::set_global_default(subscriber).unwrap();

    // Start the workers and spawn the background async tasks on the current executor.
    discord_worker.start();
    slack_worker.start();

    network_io(123).await;
    
    // Shutdown the workers and ensure their message cache is flushed.
    slack_worker.shutdown().await;
    discord_worker.shutdown().await;
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

~13–32MB
~496K SLoC