fastrace-tracing 0.1.0

A compatibility layer that connects tokio-tracing with fastrace tracing library.
Documentation
//! This example demonstrates how to use fastrace-tracing to capture spans
//! generated by the tracing library and forward them to fastrace.

use fastrace::collector::Config;
use fastrace::collector::ConsoleReporter;
use fastrace::prelude::SpanContext;
use fastrace_tracing::FastraceCompatLayer;
use tracing_subscriber::Registry;
use tracing_subscriber::layer::SubscriberExt;

fn main() {
    // Set up fastrace with the console reporter.
    fastrace::set_reporter(ConsoleReporter, Config::default());

    // Create a tracing subscriber with FastraceCompatLayer.
    let subscriber = Registry::default().with(FastraceCompatLayer::new());
    tracing::subscriber::set_global_default(subscriber).unwrap();

    {
        // Create a fastrace root span that will start a new trace.
        let root = fastrace::Span::root("root", SpanContext::random());

        // Set a fastrace span as the local parent - this is critical for connecting the
        // tokio-tracing spans with the fastrace span.
        let _guard = root.set_local_parent();

        // Call a function that will create tokio-tracing spans.
        make_traces();
    }

    // Make sure all spans are flushed to the reporter.
    fastrace::flush();
}

fn make_traces() {
    // Create a tokio-tracing span.
    let span = tracing::span!(tracing::Level::TRACE, "send request", work_units = 2);
    let _enter = span.enter();

    // Create a tokio-tracing event.
    tracing::error!("This event will be logged in the root span.");
}