Crates.io | fastrace-tracing |
lib.rs | fastrace-tracing |
version | 0.1.1 |
created_at | 2025-03-24 18:32:38.950641+00 |
updated_at | 2025-03-27 13:19:22.77066+00 |
description | A compatibility layer that connects tokio-tracing with fastrace tracing library. |
homepage | |
repository | https://github.com/fast/fastrace-tracing |
max_upload_size | |
id | 1604159 |
size | 56,833 |
A compatibility layer that connects toiok-tracing with the fastrace tracing library.
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:
fastrace
in your application but depend on libraries instrumented with tokio-tracing
tokio-tracing
to fastrace
incrementallyAdd 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();
Check out the examples directory for more detailed usage examples.
This project is licensed under the Apache-2.0 license.