diff --git a/README.md b/README.md index 722d941d..b09d119d 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Features: - [Docs] - [Examples] - [FAQ](#faq) +- [Migrating from tracing](#migrating-from-tokio-tracing) ## Getting Started @@ -159,17 +160,18 @@ The concept of 'level' may not be an optimal feature for tracing systems. While In this context, fastrace offers a more efficient solution by filtering out entire traces that are not of interest through its unique [tail-sampling](https://opentelemetry.io/blog/2022/tail-sampling/) design. Therefore, the concept of 'level', borrowed directly from logging systems, may not be suitable for fastrace. -### Will fastrace support OpenTelemetry feature 'X'? +## Migrating from tokio-tracing -fastrace is focused on high performance tracing only. You can open an issue for the missing tracing features you want to have. +If you're using the [tokio-tracing](https://github.com/tokio-rs/tracing) ecosystem and want to switch to fastrace for better performance, you can use [fastrace-tracing](https://github.com/fast/fastrace-tracing) to make the transition easier. -Note that we always prioritize performance over features, so that not all tracing feature requests may be accepted. +The `fastrace-tracing` crate provides a compatibility layer that lets you capture spans from libraries instrumented with `tokio-tracing` in two lines of code: -### What's the status of this library? - -**API Unstable**: The API is not stabilized yet, may be changed in the future. +```rust +let subscriber = tracing_subscriber::Registry::default().with(fastrace_tracing::FastraceCompatLayer::new()); +tracing::subscriber::set_global_default(subscriber).unwrap(); +``` -**Code base Tested**: fastrace has been tested with high coverage. However, applications utilizing fastrace have not been widely deployed, so that fastrace is currently **NOT** regarded as battle-tested. +For more details, refer to the [fastrace-tracing documentation](https://docs.rs/fastrace-tracing). [Docs]: https://docs.rs/fastrace/ [Examples]: https://github.com/fast/fastrace/tree/main/fastrace/examples diff --git a/fastrace/src/collector/id.rs b/fastrace/src/collector/id.rs index 64e43136..531f6fb5 100644 --- a/fastrace/src/collector/id.rs +++ b/fastrace/src/collector/id.rs @@ -78,6 +78,7 @@ impl SpanId { SpanId(rand::random()) } + // TODO: consider using `random()`. #[inline] /// Create a non-zero `SpanId` pub(crate) fn next_id() -> SpanId { @@ -128,7 +129,7 @@ impl<'de> serde::Deserialize<'de> for SpanId { /// /// [`TraceId`]: crate::collector::TraceId /// [`SpanId`]: crate::collector::SpanId -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug)] pub struct SpanContext { pub trace_id: TraceId, pub span_id: SpanId, @@ -328,6 +329,12 @@ impl SpanContext { } } +impl Default for SpanContext { + fn default() -> Self { + Self::random() + } +} + #[cfg(test)] mod tests { use std::collections::HashSet;