From 6f684e790a22c6d9164533ff89c059a49e3c1d55 Mon Sep 17 00:00:00 2001 From: Andy Lok Date: Wed, 7 Feb 2024 21:10:39 +0800 Subject: [PATCH 1/4] chore: refactor things Signed-off-by: Andy Lok --- CONTRIBUTORS | 11 +++++++++++ minitrace-futures/Cargo.toml | 7 ++++--- minitrace-futures/LICENSE | 1 + minitrace-futures/README.md | 2 +- minitrace-futures/src/lib.rs | 30 +++++++++++++++++++----------- 5 files changed, 36 insertions(+), 15 deletions(-) create mode 120000 minitrace-futures/LICENSE 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-futures/Cargo.toml b/minitrace-futures/Cargo.toml index 7bf4ed56..ee7f6e36 100644 --- a/minitrace-futures/Cargo.toml +++ b/minitrace-futures/Cargo.toml @@ -1,15 +1,16 @@ [package] name = "minitrace-futures" version = "0.6.3" -edition = "2021" +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" 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..e0653fd5 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`] @@ -50,9 +46,18 @@ pub trait Instrumented: Sized { /// /// # } /// ``` - /// - /// 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`] @@ -88,7 +93,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, From d8cade96b3bfcecdd4d36bb5c9c7c0dc0560435e Mon Sep 17 00:00:00 2001 From: Andy Lok Date: Wed, 7 Feb 2024 21:19:21 +0800 Subject: [PATCH 2/4] fix Signed-off-by: Andy Lok --- minitrace-futures/src/lib.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/minitrace-futures/src/lib.rs b/minitrace-futures/src/lib.rs index e0653fd5..4494f44e 100644 --- a/minitrace-futures/src/lib.rs +++ b/minitrace-futures/src/lib.rs @@ -27,15 +27,15 @@ pub trait StreamExt: futures::Stream + 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); /// @@ -43,7 +43,6 @@ pub trait StreamExt: futures::Stream + Sized { /// assert_eq!(s.next().await.unwrap(), 1); /// assert_eq!(s.next().await, None); /// // span ends here. - /// /// # } /// ``` fn in_span(self, span: Span) -> InSpan { @@ -72,17 +71,16 @@ pub trait SinkExt: futures::Sink + 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 { From 457271d5144522f641b96569901dadec7bcc3655 Mon Sep 17 00:00:00 2001 From: Andy Lok Date: Wed, 7 Feb 2024 21:22:53 +0800 Subject: [PATCH 3/4] fix Signed-off-by: Andy Lok --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 771ffeed..1926fdc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add `LocalSpan::add_property` and `LocalSpan::add_properties`. - Add `Config::report_before_root_finish`. +- Add new crate `minitrace-futures`. ## v0.6.3 From cf2283b64aa63259a4e021ce2f994dae48c28308 Mon Sep 17 00:00:00 2001 From: Andy Lok Date: Thu, 8 Feb 2024 13:18:28 +0800 Subject: [PATCH 4/4] bump 0.6.4 Signed-off-by: Andy Lok --- CHANGELOG.md | 2 ++ minitrace-datadog/Cargo.toml | 4 ++-- minitrace-futures/Cargo.toml | 4 ++-- minitrace-jaeger/Cargo.toml | 4 ++-- minitrace-macro/Cargo.toml | 4 ++-- minitrace-opentelemetry/Cargo.toml | 4 ++-- minitrace/Cargo.toml | 10 +++++----- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1926fdc2..fb9402b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +## v0.6.4 + - Add `LocalSpan::add_property` and `LocalSpan::add_properties`. - Add `Config::report_before_root_finish`. - Add new crate `minitrace-futures`. 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 ee7f6e36..3f2b2cdd 100644 --- a/minitrace-futures/Cargo.toml +++ b/minitrace-futures/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minitrace-futures" -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", "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-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"] }