pub trait WithEventContext: Future {
// Provided method
fn with_event_context(
self,
context_data: ContextData,
) -> EventContextFuture<Self> ⓘ
where Self: Sized { ... }
}Expand description
Extension trait for propagating event context across async boundaries.
This trait is automatically implemented for all Future types and provides
the with_event_context method to carry context data across async operations
like tokio::spawn, tokio::task::yield_now(), and other async boundaries
where thread-local storage is not preserved.
§Examples
use es_entity::context::{EventContext, WithEventContext};
async fn example() {
let mut ctx = EventContext::current();
ctx.insert("request_id", &"abc123").unwrap();
let data = ctx.data();
tokio::spawn(async {
// Context is available here
let current = EventContext::current();
// current now has the request_id from the parent
}.with_event_context(data)).await.unwrap();
}Provided Methods§
Sourcefn with_event_context(
self,
context_data: ContextData,
) -> EventContextFuture<Self> ⓘwhere
Self: Sized,
fn with_event_context(
self,
context_data: ContextData,
) -> EventContextFuture<Self> ⓘwhere
Self: Sized,
Wraps this future with event context data.
This method ensures that when the future is polled, the provided context data will be available as the current event context. This is essential for maintaining context across async boundaries where the original thread-local context is not available.
§Arguments
context_data- The context data to make available during future execution
§Returns
Returns an EventContextFuture that will poll the wrapped future with
the provided context active.