Open
Conversation
Ruby 3.4+ changed backtrace label from 'method_name' to 'ClassName#method_name'. Use assert_includes to handle both formats.
Add JsonLogFormatter for JSON-formatted log output controlled by AWS_LAMBDA_LOG_FORMAT and AWS_LAMBDA_LOG_LEVEL environment variables. Refactor TelemetryLogger initialization to apply Logger patch and runtime config before telemetry fd setup. - Add JsonLogFormatter with timestamp, level, message, requestId, and exception fields (errorType, errorMessage, stackTrace, location) - Update LoggerPatch to select formatter and log level based on env vars - Fix LogFormatter to append newline for consistency - Fix backtrace regex to handle both Ruby < 3.4 and 3.4+ formats - Upgrade Dockerfile.rie base image to Ruby 3.4 - Relax bundler development dependency to >= 2.0
trivenay
reviewed
Mar 11, 2026
| progname: progname, | ||
| msg: msg2str(msg) | ||
| } | ||
| "#{formatted.encode('UTF-8')}\n" |
There was a problem hiding this comment.
Do we rather want to do formatted.encode('UTF-8', invalid: :replace, undef: :replace, replace: '�')
There was a problem hiding this comment.
To not make bad characters fail @maxday ?
| @@ -1,12 +1,65 @@ | |||
| # frozen_string_literal: true | |||
There was a problem hiding this comment.
IN this PR I see we are patching both Kernel puts and also logger -> Not this is not usual - For all runtimes we just choose 1 thing and then patch that. For nodejs it's console for python logger. Not sure if we should do both. This is becoming hard to follow. DO we need to patch Kernel.puts?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes:
Add structured JSON logging support to the Ruby RIC, consistent with
the structured logging behavior in other Lambda managed runtimes (Python, Node.js, etc.).
When
AWS_LAMBDA_LOG_FORMAT=JSON, each log output is a JSON object containingat least four key-value pairs:
timestamp– the time the log message was generated (ISO 8601, UTC)level– the log level assigned to the message (DEBUG, INFO, WARN, ERROR, FATAL)message– the contents of the log messagerequestId– the unique request ID for the function invocationThis PR includes two commits:
fix: Update xray_cause_test for Ruby 3.4+ backtrace format
Thread::Backtrace::Location#labelfrommethod_nametoClassName#method_name. Useassert_includesto handle both formats.feat: Add structured JSON logging support
LambdaLogFormatter(JSON mode) with structured fields including exception supportLoggerPatchto select formatter and log level based on environment variablesTelemetryLoggerinitialization to apply Logger patch and runtime config before telemetry fd setupLogFormatter(TEXT mode) to append newline for consistencyLambdaLogFormatter,LambdaLogger, andLoggerPatchTarget (OCI, Managed Runtime, both):
Both
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Example Usage:
Output without
AWS_LAMBDA_LOG_FORMAT:I, [2026-03-10T22:30:46.745494 #16] INFO 3244ba10-b213-4742-9cbc-fcc611f42625 -- : Inside the handler functionOutput with
AWS_LAMBDA_LOG_FORMAT=JSON:{ "timestamp":"2026-03-10T21:37:36.350555Z", "level":"INFO", "message":"Inside the handler function", "requestId":"d1491d62-2ed4-4d08-a1be-feea698100f7" }Example exceptions:
Output without
AWS_LAMBDA_LOG_FORMAT:Output with
AWS_LAMBDA_LOG_FORMAT=JSON:{ "timestamp":"2026-03-10T22:51:58.675676Z", "level":"ERROR", "message":"something went wrong", "requestId":"f1890346-7a2f-4adf-95de-d90ba9f7d1b8", "errorType":"RuntimeError", "errorMessage":"something went wrong", "stackTrace":["/var/task/lambda_function.rb:6:in 'Object#lambda_handler'","/var/runtime/gems/aws_lambda_ric-3.1.3/lib/aws_lambda_ric/lambda_handler.rb:28:in 'LambdaHandler#call_handler'","/var/runtime/gems/aws_lambda_ric-3.1.3/lib/aws_lambda_ric.rb:86:in 'AwsLambdaRIC::LambdaRunner#run_user_code'","/var/runtime/gems/aws_lambda_ric-3.1.3/lib/aws_lambda_ric.rb:64:in 'AwsLambdaRIC::LambdaRunner#start_runtime_loop'","/var/runtime/gems/aws_lambda_ric-3.1.3/lib/aws_lambda_ric.rb:47:in 'AwsLambdaRIC::LambdaRunner#run'","/var/runtime/gems/aws_lambda_ric-3.1.3/lib/aws_lambda_ric.rb:235:in 'AwsLambdaRIC::Bootstrap#bootstrap_handler'","/var/runtime/gems/aws_lambda_ric-3.1.3/lib/aws_lambda_ric.rb:217:in 'AwsLambdaRIC::Bootstrap#start'","/var/runtime/index.rb:4:in '<main>'"], "location":"/var/task/lambda_function.rb:Object#lambda_handler:6" }