use aws_sdk_lambda::primitives::Blob;
use lambda_extension::{tracing, Error, Extension, LambdaLog, LambdaLogRecord, Service, SharedService};
use std::{future::Future, pin::Pin, task::Poll};
use tracing::span::Record;
#[derive(Clone)]
struct FirehoseLogsProcessor {}
impl FirehoseLogsProcessor {
pub fn new() -> Self {}
}
impl Service<Vec<LambdaLog>> for FirehoseLogsProcessor {
type Response = ();
type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, _cx: &mut core::task::Context<'_>) -> core::task::Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, logs: Vec<LambdaLog>) -> Self::Future {
let mut records = Vec::with_capacity(logs.len());
for log in logs {
match log.record {
LambdaLogRecord::Function(record) => {
records.push(Record::builder().data(Blob::new(record.as_bytes())).build())
}
_ => unreachable!(),
}
}
todo!()
}
}
#[tokio::main]
async fn main() -> Result<(), Error> {
tracing::init_default_subscriber();
let client = aws_config::load_defaults(aws_config::BehaviorVersion::v2023_11_09()).await;
let logs_processor = SharedService::new(FirehoseLogsProcessor::new());
Extension::new()
.with_log_types(&["function"])
.with_logs_processor(logs_processor)
.run()
.await?;
Ok(())
}