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>>>
impl Extension<'_, Identity<LambdaEvent>, MakeIdentity<Vec<LambdaLog>>, MakeIdentity<Vec<LambdaTelemetry>>>
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,
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,
Sourcepub fn with_extension_name(self, extension_name: &'a str) -> Self
pub fn with_extension_name(self, extension_name: &'a str) -> Self
Create a new Extension with a given extension name
Sourcepub fn with_events(self, events: &'a [&'a str]) -> Self
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.
Sourcepub fn with_events_processor<N>(self, ep: N) -> Extension<'a, N, L, T, TL>
pub fn with_events_processor<N>(self, ep: N) -> Extension<'a, N, L, T, TL>
Create a new Extension with a service that receives Lambda events.
Sourcepub fn with_logs_processor<N, NS>(self, lp: N) -> Extension<'a, E, N, T, TL>
pub fn with_logs_processor<N, NS>(self, lp: N) -> Extension<'a, E, N, T, TL>
Create a new Extension with a service that receives Lambda logs.
Sourcepub fn with_log_types(self, log_types: &'a [&'a str]) -> Self
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.
Sourcepub fn with_log_buffering(self, lb: LogBuffering) -> Self
pub fn with_log_buffering(self, lb: LogBuffering) -> Self
Create a new Extension with specific configuration to buffer logs.
Sourcepub fn with_log_port_number(self, port_number: u16) -> Self
pub fn with_log_port_number(self, port_number: u16) -> Self
Create a new Extension with a different port number to listen to logs.
Sourcepub fn with_telemetry_processor<N, NS>(
self,
lp: N,
) -> Extension<'a, E, L, N, TL>
pub fn with_telemetry_processor<N, NS>( self, lp: N, ) -> Extension<'a, E, L, N, TL>
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.
Sourcepub fn with_telemetry_types(self, telemetry_types: &'a [&'a str]) -> Self
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.
Sourcepub fn with_telemetry_buffering(self, lb: LogBuffering) -> Self
pub fn with_telemetry_buffering(self, lb: LogBuffering) -> Self
Create a new Extension with specific configuration to buffer telemetry.
Sourcepub fn with_telemetry_port_number(self, port_number: u16) -> Self
pub fn with_telemetry_port_number(self, port_number: u16) -> Self
Create a new Extension with a different port number to listen to telemetry.
Sourcepub async fn register(self) -> Result<RegisteredExtension<E>, Error>
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§impl<'a, E, L> Extension<'a, E, L, MakeIdentity<Vec<LambdaTelemetry>>>
impl<'a, E, L> Extension<'a, E, L, MakeIdentity<Vec<LambdaTelemetry>>>
Sourcepub fn with_telemetry_record_type<N>(
self,
) -> Extension<'a, E, L, MakeIdentity<Vec<LambdaTelemetry<N>>>, N>
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)));