Skip to content

Add structured JSON logging support#58

Open
anzheyazzz wants to merge 1 commit intomainfrom
anzhey/structured-logging
Open

Add structured JSON logging support#58
anzheyazzz wants to merge 1 commit intomainfrom
anzhey/structured-logging

Conversation

@anzheyazzz
Copy link

@anzheyazzz anzheyazzz commented Mar 10, 2026

Description of changes:

Add structured logging support to the Ruby RIC on the Logger path, 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 containing
at 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 message
  • requestId – the unique request ID for the function invocation

This PR includes the following changes:

  • Add structured JSON logging support for the Ruby Logger path
  • Apply formatter and log level selection based on AWS_LAMBDA_LOG_FORMAT and AWS_LAMBDA_LOG_LEVEL
  • Make this behavior work consistently with and without telemetry fd, with unit test coverage

Target (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:

require 'logger'

def lambda_handler(event:, context:)
    logger = Logger.new($stdout)
    logger.info("Inside the handler function")
end

Output without AWS_LAMBDA_LOG_FORMAT:

I, [2026-03-10T22:30:46.745494 #16] INFO 3244ba10-b213-4742-9cbc-fcc611f42625 -- : Inside the handler function

Output 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"
}

@anzheyazzz anzheyazzz requested a review from maxday March 10, 2026 22:55
@anzheyazzz anzheyazzz force-pushed the anzhey/structured-logging branch from f152901 to 04b46a4 Compare March 16, 2026 16:04
@anzheyazzz anzheyazzz force-pushed the anzhey/structured-logging branch from 04b46a4 to 6d392d3 Compare March 18, 2026 16:22
@anzheyazzz anzheyazzz requested a review from trivenay March 18, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants