Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tracing-futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ license = "MIT"
default = ["std-future", "std"]
futures-01 = ["futures_01", "std"]
futures-03 = ["std-future", "futures", "futures-task", "std"]
std-future = ["pin-project"]
std-future = ["pin-project-lite"]
std = ["tracing/std"]

[dependencies]
futures_01 = { package = "futures", version = "0.1", optional = true }
futures = { version = "0.3.0", optional = true }
futures-task = { version = "0.3", optional = true }
pin-project = { version = "1.0", optional = true }
pin-project-lite = { version = "0.2.4", optional = true }
tracing = { path = "../tracing", version = "0.2", default-features = false }
tokio-executor = { version = "0.1", optional = true }
tokio = { version = "0.1", optional = true }
Expand Down
40 changes: 27 additions & 13 deletions tracing-futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "std-future")]
use pin_project::pin_project;
use pin_project_lite::pin_project;

#[cfg(feature = "std-future")]
use core::{pin::Pin, task::Context};
Expand Down Expand Up @@ -239,30 +239,44 @@ pub trait WithCollector: Sized {
}
}

#[cfg(feature = "std-future")]
pin_project! {
/// A future, stream, sink, or executor that has been instrumented with a `tracing` span.
#[derive(Debug, Clone)]
pub struct Instrumented<T> {
#[pin]
inner: T,
span: Span,
}
}

/// A future, stream, sink, or executor that has been instrumented with a `tracing` span.
#[cfg_attr(feature = "std-future", pin_project)]
#[cfg(not(feature = "std-future"))]
#[derive(Debug, Clone)]
pub struct Instrumented<T> {
#[cfg(feature = "std-future")]
#[pin]
inner: T,
#[cfg(not(feature = "std-future"))]
inner: T,
span: Span,
}

#[cfg(all(feature = "std", feature = "std-future"))]
pin_project! {
/// A future, stream, sink, or executor that has been instrumented with a
/// `tracing` subscriber.
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[derive(Clone, Debug)]
pub struct WithDispatch<T> {
#[pin]
inner: T,
dispatch: Dispatch,
}
}

/// A future, stream, sink, or executor that has been instrumented with a
/// `tracing` subscriber.
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(feature = "std-future")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg_attr(feature = "std-future", pin_project)]
#[derive(Clone, Debug)]
pub struct WithDispatch<T> {
// cfg_attr doesn't work inside structs, apparently...
#[cfg(feature = "std-future")]
#[pin]
inner: T,
#[cfg(not(feature = "std-future"))]
inner: T,
dispatch: Dispatch,
}
Expand Down
4 changes: 2 additions & 2 deletions tracing-tower/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ license = "MIT"
default = ["tower-layer", "tower-make", "http"]
tower-make = [
"tower_make",
"pin-project",
"pin-project-lite",
]

[dependencies]
Expand All @@ -30,7 +30,7 @@ futures = "0.3"
tower-service = "0.3"
tower-layer = { version = "0.3", optional = true }
tower_make = { package = "tower-make", version = "0.3", optional = true }
pin-project = { version = "1.0", optional = true }
pin-project-lite = { version = "0.2.4", optional = true }
http = { version = "0.2", optional = true }

[badges]
Expand Down
17 changes: 9 additions & 8 deletions tracing-tower/src/request_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub use self::make::MakeService;
#[cfg_attr(docsrs, doc(cfg(feature = "tower-make")))]
pub mod make {
use super::*;
use pin_project::pin_project;
use pin_project_lite::pin_project;

#[derive(Debug)]
pub struct MakeService<S, R, G = fn(&R) -> tracing::Span> {
Expand All @@ -99,13 +99,14 @@ pub mod make {
_p: PhantomData<fn(T, R)>,
}

#[pin_project]
#[derive(Debug)]
pub struct MakeFuture<F, R, G = fn(&R) -> tracing::Span> {
get_span: Option<G>,
#[pin]
inner: F,
_p: PhantomData<fn(R)>,
pin_project! {
#[derive(Debug)]
pub struct MakeFuture<F, R, G = fn(&R) -> tracing::Span> {
get_span: Option<G>,
#[pin]
inner: F,
_p: PhantomData<fn(R)>,
}
}

#[cfg(feature = "tower-layer")]
Expand Down
15 changes: 8 additions & 7 deletions tracing-tower/src/service_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod layer {
#[cfg_attr(docsrs, doc(cfg(feature = "tower-layer")))]
pub mod make {
use super::*;
use pin_project::pin_project;
use pin_project_lite::pin_project;

#[derive(Debug)]
pub struct MakeService<M, T, R, G = fn(&T) -> tracing::Span>
Expand All @@ -91,12 +91,13 @@ pub mod make {
_p: PhantomData<fn(T, R)>,
}

#[pin_project]
#[derive(Debug)]
pub struct MakeFuture<F> {
#[pin]
inner: F,
span: Option<tracing::Span>,
pin_project! {
#[derive(Debug)]
pub struct MakeFuture<F> {
#[pin]
inner: F,
span: Option<tracing::Span>,
}
}

#[derive(Debug)]
Expand Down