Expand description
§fastrace-tracing
A compatibility layer that connects toiok-tracing with the fastrace tracing library.
§Overview
fastrace-tracing allows you to capture spans and events from libraries that use tokio-tracing and forward them to fastrace. This is particularly useful when:
- You’re using
fastracein your application but depend on libraries instrumented withtokio-tracing - You want to migrate from
tokio-tracingtofastraceincrementally
§Getting Started
Add fastrace-tracing to your project:
[dependencies] fastrace = { version = "0.7", features = ["enable"] } fastrace-tracing = "0.1" tracing = { version = "0.1", features = ["log"] } tracing-subscriber = "0.3"Set up the compatibility layer:
use fastrace::collector::{Config, ConsoleReporter}; use fastrace::prelude::*; use tracing_subscriber::layer::SubscriberExt; // Set up tokio-tracing with the fastrace compatibility layer. let subscriber = tracing_subscriber::Registry::default() .with(fastrace_tracing::FastraceCompatLayer::new()); tracing::subscriber::set_global_default(subscriber).unwrap(); // Initialize fastrace. fastrace::set_reporter(ConsoleReporter, Config::default()); // Initialize logging. logforth::stderr().apply(); { // Create a fastrace root span. let root = Span::root("my-application", 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(); // Spans from tokio-tracing will be captured by fastrace. let span = tracing::span!(tracing::Level::INFO, "my_operation"); let _enter = span.enter(); // Events from tokio-tracing will be captured by both fastrace and log. tracing::info!("This will be captured by fastrace"); } // Flush any remaining traces before the program exits. fastrace::flush();§Examples
Check out the examples directory for more detailed usage examples.
§License
This project is licensed under the Apache-2.0 license.
Structs§
- Fastrace
Compat Layer - A compatibility layer for using libraries instrumented with
tokio-tracingin applications usingfastrace.