-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c589841
commit f781de0
Showing
3 changed files
with
39 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::Context; | ||
use crate::trace::WithContext; | ||
|
||
/// Extension trait allowing futures, streams, and sinks to be traced with a span. | ||
pub trait FutureExt: Sized { | ||
/// Attaches the provided [`Context`] to this type, returning a `WithContext` | ||
/// wrapper. | ||
/// | ||
/// When the wrapped type is a future, stream, or sink, the attached context | ||
/// will be set as current while it is being polled. | ||
/// | ||
/// [`Context`]: Context | ||
fn with_context(self, otel_cx: Context) -> WithContext<Self> { | ||
WithContext { | ||
inner: self, | ||
otel_cx, | ||
} | ||
} | ||
|
||
/// Attaches the current [`Context`] to this type, returning a `WithContext` | ||
/// wrapper. | ||
/// | ||
/// When the wrapped type is a future, stream, or sink, the attached context | ||
/// will be set as the default while it is being polled. | ||
/// | ||
/// [`Context`]: Context | ||
fn with_current_context(self) -> WithContext<Self> { | ||
let otel_cx = Context::current(); | ||
self.with_context(otel_cx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
mod context_store; | ||
mod future_ext; | ||
|
||
pub use context_store::Context; | ||
pub use context_store::ContextGuard; | ||
pub use context_store::ContextGuard; | ||
pub use future_ext::FutureExt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters