-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support structured JSON logging for errors #533
Comments
Need to play with it a bit! :)
|
Thanks for taking a peek!
Nothing special is required - as long as
I'm not sure about that either. It's really only an issue if those calls are / can be expensive, but I didn't see it doing anything substantial except for panic recovery and trace info, which is exactly what I'm hoping to get here.
There's a doc - scroll to the "JSON format for application logs" section - they detail how the shape looks in the managed runtimes (don't even get me started on |
AWS released advanced logging controls for Lambda.
On the whole, it works great with the
slog
package in Go 1.21 on theprovided.2023
runtime for logging from Go functions. However,aws-lambda-go
handles the logging of function errors, which are written in their own format that was decided on long before AWS released structured logging options.When JSON logging is enabled on a function, any unstructured log entry will be automatically reshaped to JSON and will set the log level to
INFO
. Function errors handled byaws-lambda-go
have this problem, which means that the only way to see function errors in the logs is to set the application log level toINFO
.Here's the complete code that demonstrates the following.
In the CloudFormation for a function, we'll set the
LoggingConfig
and (for now) we'll setApplicationLogLevel
to INFO.Given the following code, we expect the usual Lambda system log entries, plus an application-generated
info message
,warn message
,error message
, and the panic log entry.This works as expected, but notice that the level for the errors are
INFO
.Now we'll update the
LoggingConfig
to set the application log level toERROR
(and we'll set the system level to warn to quiet things down).Re-run the function and take a look at the CloudWatch Logs. Since the error output logging is getting shoved into
INFO
level, it's not shown at all. We know that the function errored from the platform-level log, but won't be able to see what happened.In addition to the
AWS_LAMBDA_LOG_LEVEL
env var demonstrated above, Lambda now also exposesAWS_LAMBDA_LOG_FORMAT
, which could be used here inaws-lambda-go
to determine whether or not to write the log entry with a predefined JSON structure without being a breaking change to this library.In summary, it'd be great to be able to use
ERROR
level logging in Lambda applications and be able to see errors fromaws-lambda-go
. Thank you!The text was updated successfully, but these errors were encountered: