Skip to main content

Extension

Struct Extension 

Source
pub struct Extension<'a, E, L, T, TL = String> { /* private fields */ }
Expand description

An Extension that runs event, log and telemetry processors

Implementations§

Source§

impl Extension<'_, Identity<LambdaEvent>, MakeIdentity<Vec<LambdaLog>>, MakeIdentity<Vec<LambdaTelemetry>>>

Source

pub fn new() -> Self

Create a new base Extension with a no-op events processor

Source§

impl<'a, E, L, T, TL> Extension<'a, E, L, T, TL>
where E: Service<LambdaEvent>, E::Future: Future<Output = Result<(), E::Error>>, E::Error: Into<Error> + Display + Debug, L: MakeService<(), Vec<LambdaLog>, Response = ()> + Send + Sync + 'static, L::Service: Service<Vec<LambdaLog>, Response = ()> + Send + Sync, <L::Service as Service<Vec<LambdaLog>>>::Future: Send + 'a, L::Error: Into<Error> + Debug, L::MakeError: Into<Error> + Debug, L::Future: Send, T: MakeService<(), Vec<LambdaTelemetry<TL>>, Response = ()> + Send + Sync + 'static, T::Service: Service<Vec<LambdaTelemetry<TL>>, Response = ()> + Send + Sync, <T::Service as Service<Vec<LambdaTelemetry<TL>>>>::Future: Send + 'a, T::Error: Into<Error> + Debug, T::MakeError: Into<Error> + Debug, T::Future: Send, TL: DeserializeOwned + Send + 'static,

Source

pub fn with_extension_name(self, extension_name: &'a str) -> Self

Create a new Extension with a given extension name

Source

pub fn with_events(self, events: &'a [&'a str]) -> Self

Create a new Extension with a list of given events. The only accepted events are INVOKE and SHUTDOWN.

Source

pub fn with_events_processor<N>(self, ep: N) -> Extension<'a, N, L, T, TL>
where N: Service<LambdaEvent>, N::Future: Future<Output = Result<(), N::Error>>, N::Error: Into<Error> + Display,

Create a new Extension with a service that receives Lambda events.

Source

pub fn with_logs_processor<N, NS>(self, lp: N) -> Extension<'a, E, N, T, TL>
where N: Service<()>, N::Future: Future<Output = Result<NS, N::Error>>, N::Error: Into<Error> + Display,

Create a new Extension with a service that receives Lambda logs.

Source

pub fn with_log_types(self, log_types: &'a [&'a str]) -> Self

Create a new Extension with a list of logs types to subscribe. The only accepted log types are function, platform, and extension.

Source

pub fn with_log_buffering(self, lb: LogBuffering) -> Self

Create a new Extension with specific configuration to buffer logs.

Source

pub fn with_log_port_number(self, port_number: u16) -> Self

Create a new Extension with a different port number to listen to logs.

Source

pub fn with_telemetry_processor<N, NS>( self, lp: N, ) -> Extension<'a, E, L, N, TL>
where N: Service<()>, N::Future: Future<Output = Result<NS, N::Error>>, N::Error: Into<Error> + Display,

Create a new Extension with a service that receives Lambda telemetry data.

By default, telemetry log records are deserialized as String, but it’s possible to configure Lambda functions to emit logs in JSON format. For more information, refer to Self::with_telemetry_record_type.

Source

pub fn with_telemetry_types(self, telemetry_types: &'a [&'a str]) -> Self

Create a new Extension with a list of telemetry types to subscribe. The only accepted telemetry types are function, platform, and extension.

Source

pub fn with_telemetry_buffering(self, lb: LogBuffering) -> Self

Create a new Extension with specific configuration to buffer telemetry.

Source

pub fn with_telemetry_port_number(self, port_number: u16) -> Self

Create a new Extension with a different port number to listen to telemetry.

Source

pub async fn register(self) -> Result<RegisteredExtension<E>, Error>

Register the extension.

Performs the init phase Lambda lifecycle operations to register the extension. When implementing an internal Lambda extension, it is safe to call lambda_runtime::run once the future returned by this function resolves.

Source

pub async fn run(self) -> Result<(), Error>

Execute the given extension.

Source§

impl<'a, E, L> Extension<'a, E, L, MakeIdentity<Vec<LambdaTelemetry>>>

Source

pub fn with_telemetry_record_type<N>( self, ) -> Extension<'a, E, L, MakeIdentity<Vec<LambdaTelemetry<N>>>, N>

Set the deserialization type for telemetry log records.

By default, telemetry log records are deserialized as String, but it’s possible to configure Lambda functions to emit logs in JSON format. Use this method to deserialize into a different type, such as serde_json::Value.

Must be called before Self::with_telemetry_processor.

use lambda_extension::{Extension, LambdaTelemetry, SharedService, service_fn};

async fn handler(events: Vec<LambdaTelemetry<serde_json::Value>>) -> Result<(), lambda_extension::Error> {
    for event in &events {
        println!("{event:?}");
    }
    Ok(())
}

let _ext = Extension::new()
    .with_telemetry_record_type::<serde_json::Value>()
    .with_telemetry_processor(SharedService::new(service_fn(handler)));

Trait Implementations§

Source§

impl Default for Extension<'_, Identity<LambdaEvent>, MakeIdentity<Vec<LambdaLog>>, MakeIdentity<Vec<LambdaTelemetry>>>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a, E, L, T, TL> Freeze for Extension<'a, E, L, T, TL>
where E: Freeze, L: Freeze, T: Freeze,

§

impl<'a, E, L, T, TL> RefUnwindSafe for Extension<'a, E, L, T, TL>

§

impl<'a, E, L, T, TL> Send for Extension<'a, E, L, T, TL>
where E: Send, L: Send, T: Send,

§

impl<'a, E, L, T, TL> Sync for Extension<'a, E, L, T, TL>
where E: Sync, L: Sync, T: Sync,

§

impl<'a, E, L, T, TL> Unpin for Extension<'a, E, L, T, TL>
where E: Unpin, L: Unpin, T: Unpin,

§

impl<'a, E, L, T, TL> UnsafeUnpin for Extension<'a, E, L, T, TL>

§

impl<'a, E, L, T, TL> UnwindSafe for Extension<'a, E, L, T, TL>
where E: UnwindSafe, L: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more