Interceptor

Trait Interceptor 

Source
pub trait Interceptor<T = ()>: Send + Sync {
    // Provided methods
    fn before_request<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 mut BeforeRequestContext<'life2, T>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn after_response<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 AfterResponseContext<'life2, T>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_stream_chunk<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 StreamChunkContext<'life2, T>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_stream_end<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 StreamEndContext<'life2, T>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_error<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 ErrorContext<'life2, T>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Trait for implementing interceptors.

Interceptors can hook into various stages of the request/response lifecycle. All methods have default no-op implementations, so you only need to implement the hooks you’re interested in.

The generic type parameter T defines the state type that will be passed through the request lifecycle. Use () (the default) for simple interceptors that don’t need to maintain state across hooks.

Provided Methods§

Source

fn before_request<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ctx: &'life1 mut BeforeRequestContext<'life2, T>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called before a request is sent.

This method can modify the state that will be passed through the request lifecycle.

Source

fn after_response<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ctx: &'life1 AfterResponseContext<'life2, T>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called after a successful non-streaming response is received.

Source

fn on_stream_chunk<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ctx: &'life1 StreamChunkContext<'life2, T>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called for each chunk in a streaming response.

Source

fn on_stream_end<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ctx: &'life1 StreamEndContext<'life2, T>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when a streaming response completes successfully.

Source

fn on_error<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ctx: &'life1 ErrorContext<'life2, T>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when an error occurs at any stage.

Note: This method doesn’t return a Result as it’s called during error handling and shouldn’t fail.

Implementations on Foreign Types§

Source§

impl<T: Tracer + Send + Sync> Interceptor<LangfuseState<<T as Tracer>::Span>> for Arc<LangfuseInterceptor<T>>
where T::Span: Send + Sync + 'static,

Source§

fn before_request<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 mut BeforeRequestContext<'life2, LangfuseState<T::Span>>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn after_response<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 AfterResponseContext<'life2, LangfuseState<T::Span>>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn on_stream_chunk<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 StreamChunkContext<'life2, LangfuseState<T::Span>>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn on_stream_end<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 StreamEndContext<'life2, LangfuseState<T::Span>>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn on_error<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 ErrorContext<'life2, LangfuseState<T::Span>>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Implementors§

Source§

impl<T: Tracer + Send + Sync> Interceptor<LangfuseState<<T as Tracer>::Span>> for LangfuseInterceptor<T>
where T::Span: Send + Sync + 'static,