diff --git a/CHANGELOG.md b/CHANGELOG.md index 771ffeed..fb9402b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,11 @@ ## Unreleased +## v0.6.4 + - Add `LocalSpan::add_property` and `LocalSpan::add_properties`. - Add `Config::report_before_root_finish`. +- Add new crate `minitrace-futures`. ## v0.6.3 diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c0ba81ab..b5873e67 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1,9 +1,20 @@ Thanks to the following for their help and contributions to minitrace-rust: +0xd34d10cc Andy Lok Brian Anderson +Dotan Simha +iGxnon Jiang Yinzuo +Jonathan Chuang +Mark Van de Vyver piercetrey-figure Renkai Ge Stephen Cirner +shota kizawa +TennyZhuang +Wenxuan +Xuanwo +xxchan +Yilin Chen Zhenchi diff --git a/minitrace-datadog/Cargo.toml b/minitrace-datadog/Cargo.toml index b4945211..b1b69ba5 100644 --- a/minitrace-datadog/Cargo.toml +++ b/minitrace-datadog/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minitrace-datadog" -version = "0.6.3" +version = "0.6.4" authors = ["The TiKV Project Authors"] license = "Apache-2.0" edition = "2021" @@ -14,7 +14,7 @@ keywords = ["tracing", "span", "datadog", "jaeger", "opentelemetry"] [dependencies] log = "0.4" -minitrace = { version = "0.6.3", path = "../minitrace" } +minitrace = { version = "0.6.4", path = "../minitrace" } reqwest = { version = "0.11", features = ["blocking"] } rmp-serde = "1" serde = { version = "1", features = ["derive"] } diff --git a/minitrace-futures/Cargo.toml b/minitrace-futures/Cargo.toml index 7bf4ed56..3f2b2cdd 100644 --- a/minitrace-futures/Cargo.toml +++ b/minitrace-futures/Cargo.toml @@ -1,19 +1,20 @@ [package] name = "minitrace-futures" -version = "0.6.3" -edition = "2021" +version = "0.6.4" +authors = ["The TiKV Project Authors"] license = "Apache-2.0" -description = "Utilities for instrumenting `futures` with minitrace-rust" +edition = "2021" +description = "Utilities for tracing `futures` with minitrace-rust" homepage = "https://github.com/tikv/minitrace-rust" repository = "https://github.com/tikv/minitrace-rust" documentation = "https://docs.rs/minitrace-futures" readme = "README.md" categories = ["development-tools::debugging"] -keywords = ["tracing", "span", "datadog", "jaeger", "opentelemetry"] +keywords = ["tracing", "span", "futures", "jaeger", "opentelemetry"] [dependencies] futures = "0.3" -minitrace = { version = "0.6.3", path = "../minitrace" } +minitrace = { version = "0.6.4", path = "../minitrace" } pin-project-lite = "0.2.13" [dev-dependencies] diff --git a/minitrace-futures/LICENSE b/minitrace-futures/LICENSE new file mode 120000 index 00000000..ea5b6064 --- /dev/null +++ b/minitrace-futures/LICENSE @@ -0,0 +1 @@ +../LICENSE \ No newline at end of file diff --git a/minitrace-futures/README.md b/minitrace-futures/README.md index d50d13f9..6400d488 100644 --- a/minitrace-futures/README.md +++ b/minitrace-futures/README.md @@ -4,4 +4,4 @@ [![Crates.io](https://img.shields.io/crates/v/minitrace-futures.svg)](https://crates.io/crates/minitrace-futures) [![LICENSE](https://img.shields.io/github/license/tikv/minitrace-rust.svg)](https://github.com/tikv/minitrace-rust/blob/master/LICENSE) -Some utilities for instrumenting `futures` with [`minitrace`](https://crates.io/crates/minitrace). +Some utilities for tracing `futures` with [`minitrace`](https://crates.io/crates/minitrace). diff --git a/minitrace-futures/src/lib.rs b/minitrace-futures/src/lib.rs index b45de2a6..4494f44e 100644 --- a/minitrace-futures/src/lib.rs +++ b/minitrace-futures/src/lib.rs @@ -1,3 +1,5 @@ +// Copyright 2024 TiKV Project Authors. Licensed under Apache-2.0. + #![doc = include_str!("../README.md")] use std::pin::Pin; @@ -9,14 +11,8 @@ use futures::Stream; use minitrace::Span; use pin_project_lite::pin_project; -// There is no boundary in order to support types that -// implement both stream and sink. -impl Instrumented for T {} - -/// Instrument [`futures::Stream`]s and [`futures::Sink`]s. -pub trait Instrumented: Sized { - /// For [`Stream`]s : - /// +/// An extension trait for [`futures::Stream`] that provides tracing instrument adapters. +pub trait StreamExt: futures::Stream + Sized { /// Binds a [`Span`] to the [`Stream`] that continues to record until the stream is **finished**. /// /// In addition, it sets the span as the local parent at every poll so that [`minitrace::local::LocalSpan`] @@ -31,15 +27,15 @@ pub trait Instrumented: Sized { /// use async_stream::stream; /// use futures::StreamExt; /// use minitrace::prelude::*; - /// use minitrace_futures::*; + /// use minitrace_futures::StreamExt as _; /// - /// let root = Span::root("Root", SpanContext::random()); + /// let root = Span::root("root", SpanContext::random()); /// let s = stream! { /// for i in 0..2 { /// yield i; /// } /// } - /// .in_span(Span::enter_with_parent("Task", &root)); + /// .in_span(Span::enter_with_parent("task", &root)); /// /// tokio::pin!(s); /// @@ -47,12 +43,20 @@ pub trait Instrumented: Sized { /// assert_eq!(s.next().await.unwrap(), 1); /// assert_eq!(s.next().await, None); /// // span ends here. - /// /// # } /// ``` - /// - /// For [`Sink`]s : - /// + fn in_span(self, span: Span) -> InSpan { + InSpan { + inner: self, + span: Some(span), + } + } +} + +impl StreamExt for T where T: futures::Stream {} + +/// An extension trait for [`futures::Sink`] that provides tracing instrument adapters. +pub trait SinkExt: futures::Sink + Sized { /// Binds a [`Span`] to the [`Sink`] that continues to record until the sink is **closed**. /// /// In addition, it sets the span as the local parent at every poll so that [`minitrace::local::LocalSpan`] @@ -67,17 +71,16 @@ pub trait Instrumented: Sized { /// use futures::sink; /// use futures::sink::SinkExt; /// use minitrace::prelude::*; - /// use minitrace_futures::*; + /// use minitrace_futures::SinkExt as _; /// - /// let root = Span::root("Root", SpanContext::random()); + /// let root = Span::root("root", SpanContext::random()); /// - /// let mut drain = sink::drain().in_span(Span::enter_with_parent("Task", &root)); + /// let mut drain = sink::drain().in_span(Span::enter_with_parent("task", &root)); /// /// drain.send(1).await.unwrap(); /// drain.send(2).await.unwrap(); /// drain.close().await.unwrap(); /// // span ends here. - /// /// # } /// ``` fn in_span(self, span: Span) -> InSpan { @@ -88,7 +91,10 @@ pub trait Instrumented: Sized { } } +impl SinkExt for T where T: futures::Sink {} + pin_project! { + /// Adapter for [`StreamExt::in_span()`](StreamExt::in_span) and [`SinkExt::in_span()`](SinkExt::in_span). pub struct InSpan { #[pin] inner: T, diff --git a/minitrace-jaeger/Cargo.toml b/minitrace-jaeger/Cargo.toml index 9c4839b5..4492bdbd 100644 --- a/minitrace-jaeger/Cargo.toml +++ b/minitrace-jaeger/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minitrace-jaeger" -version = "0.6.3" +version = "0.6.4" authors = ["The TiKV Project Authors"] license = "Apache-2.0" edition = "2021" @@ -14,7 +14,7 @@ keywords = ["tracing", "span", "datadog", "jaeger", "opentelemetry"] [dependencies] log = "0.4" -minitrace = { version = "0.6.3", path = "../minitrace" } +minitrace = { version = "0.6.4", path = "../minitrace" } thrift_codec = "0.2" [dev-dependencies] diff --git a/minitrace-macro/Cargo.toml b/minitrace-macro/Cargo.toml index d860338c..207c8430 100644 --- a/minitrace-macro/Cargo.toml +++ b/minitrace-macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minitrace-macro" -version = "0.6.3" +version = "0.6.4" authors = ["The TiKV Project Authors"] license = "Apache-2.0" edition = "2021" @@ -24,7 +24,7 @@ syn = { version = "1.0.84", features = ["full", "parsing", "extra-traits", "proc [dev-dependencies] logcall = "0.1.4" -minitrace = { version = "0.6.3", path = "../minitrace" } +minitrace = { version = "0.6.4", path = "../minitrace" } tokio = { version = "1", features = ["full"] } trybuild = "1" # The procedural macro `trace` only supports async-trait higher than 0.1.52 diff --git a/minitrace-opentelemetry/Cargo.toml b/minitrace-opentelemetry/Cargo.toml index 371f1bac..ba79073b 100644 --- a/minitrace-opentelemetry/Cargo.toml +++ b/minitrace-opentelemetry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minitrace-opentelemetry" -version = "0.6.3" +version = "0.6.4" authors = ["The TiKV Project Authors"] license = "Apache-2.0" edition = "2021" @@ -15,7 +15,7 @@ keywords = ["tracing", "span", "datadog", "jaeger", "opentelemetry"] [dependencies] futures = { version = "0.3", features = ["executor"] } log = "0.4" -minitrace = { version = "0.6.3", path = "../minitrace" } +minitrace = { version = "0.6.4", path = "../minitrace" } opentelemetry = { version = "0.21", features = ["trace"] } opentelemetry_sdk = { version = "0.21", features = ["trace"] } diff --git a/minitrace/Cargo.toml b/minitrace/Cargo.toml index a63b99a8..30f07720 100644 --- a/minitrace/Cargo.toml +++ b/minitrace/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minitrace" -version = "0.6.3" +version = "0.6.4" authors = ["The TiKV Project Authors"] license = "Apache-2.0" edition = "2021" @@ -17,7 +17,7 @@ enable = [] [dependencies] futures = "0.3" -minitrace-macro = { version = "0.6.3", path = "../minitrace-macro" } +minitrace-macro = { version = "0.6.4", path = "../minitrace-macro" } minstant = "0.1" parking_lot = "0.12" pin-project = "1" @@ -37,9 +37,9 @@ futures-timer = "3" log = "0.4" logcall = "0.1.4" minitrace = { path = ".", features = ["enable"] } -minitrace-datadog = { version = "0.6.3", path = "../minitrace-datadog" } -minitrace-jaeger = { version = "0.6.3", path = "../minitrace-jaeger" } -minitrace-opentelemetry = { version = "0.6.3", path = "../minitrace-opentelemetry" } +minitrace-datadog = { version = "0.6.4", path = "../minitrace-datadog" } +minitrace-jaeger = { version = "0.6.4", path = "../minitrace-jaeger" } +minitrace-opentelemetry = { version = "0.6.4", path = "../minitrace-opentelemetry" } mockall = "0.11" once_cell = "1" opentelemetry = { version = "0.21", features = ["trace"] }