-
Notifications
You must be signed in to change notification settings - Fork 376
Closed
Description
I noticed that the Rust runtime currently logs handler errors using {}
as the format:
error!("{}", err); // logs the error in CloudWatch |
However, the widely used anyhow crate will only include the error chain with {:?}
or {:#}
:
Among other things, this means that only the last error will be logged to CloudWatch and that all underlying causes are lost when using with_context to augment errors.
My current solution/workaround is to add an additional log statement like this:
#[tokio::main]
async fn main() -> Result<(), Error> {
env_logger::try_init()?;
lambda_runtime::run(handler_fn(|_: Input, _: Context| async {
let output = handler().await.map_err(|e| {
error!("{:?}", e); // log error chain to CloudWatch
e
})?;
Ok(output) as Result<Output>
}))
.await?;
Ok(())
}
Of course, this duplicates error logging to some degree and would have to be done in every Lambda function. I wonder if there's a better way of telling the runtime how to log errors?
Metadata
Metadata
Assignees
Labels
No labels