Conversation
…eLogger() instead of the raw logger parameter
There was a problem hiding this comment.
Pull request overview
This PR implements JSON structured logging support for AWS Lambda functions, aligning with AWS Lambda's advanced logging controls. The implementation adds the ability to emit logs in JSON format when AWS_LAMBDA_LOG_FORMAT=JSON is set, while maintaining full backward compatibility with existing text-based logging.
Changes:
- Introduces
LoggingConfigurationto handle environment variable parsing and logger factory logic with proper precedence rules forAWS_LAMBDA_LOG_LEVELvsLOG_LEVEL - Adds
JSONLogHandlerto format logs as JSON with Lambda-specific metadata (requestId, traceId) - Updates
LambdaRuntimeandLambdaManagedRuntimeto use the new logging configuration and create per-request loggers - Provides comprehensive JSONLogging example with deployment templates and documentation
- Updates design proposal and other documentation
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/AWSLambdaRuntime/Logging/LoggingConfiguration.swift | New file implementing logging configuration with environment variable parsing and logger factory methods |
| Sources/AWSLambdaRuntime/Logging/JSONLogHandler.swift | New file implementing JSON log handler with structured output to stderr |
| Sources/AWSLambdaRuntime/Runtime/LambdaRuntime.swift | Updated to initialize and use LoggingConfiguration, create per-request loggers |
| Sources/AWSLambdaRuntime/ManagedRuntime/LambdaManagedRuntime.swift | Updated to initialize and use LoggingConfiguration, create per-request loggers |
| Sources/AWSLambdaRuntime/Lambda.swift | Updated runLoop to create per-request loggers, deprecated old runLoop signature |
| Tests/AWSLambdaRuntimeTests/LambdaRunLoopTests.swift | Updated tests to use new runLoop signature with LoggingConfiguration |
| Sources/AWSLambdaRuntime/Docs.docc/Proposals/0002-logging.md | New design document describing the structured logging feature |
| Sources/AWSLambdaRuntime/Docs.docc/managed-instances.md | Header level adjustments for consistency |
| Sources/AWSLambdaRuntime/Docs.docc/Deployment.md | Header level adjustment for consistency |
| Examples/JSONLogging/* | Complete example demonstrating JSON logging with SAM templates and README |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sources/AWSLambdaRuntime/ManagedRuntime/LambdaManagedRuntime.swift
Outdated
Show resolved
Hide resolved
|
More feedback received on slack. Adding it here for transparency
|
89d5cee to
c19febc
Compare
|
@benrosen78 Here are a couple of changes
See c19febc {"timestamp":"2026-02-24T18:16:24.465Z","requestId":"5B9EEA11-C217-4872-B4B1-E8EE371C3B61","traceId":"Root=1-699deaf8-d3ea5e248a06d154c6518cbb;Sampled=1","level":"INFO","message":"Processing request for error"}
See 47feea9
My bad. I forgot to pass these parameters. See 184fc62 {"message":"Server started and listening","requestId":"N\/A","level":"INFO","timestamp":"2026-02-24T18:43:11.688Z","metadata":{"port":"7000","host":"\"127.0.0.1\""},"traceId":"N\/A","file":"AWSLambdaRuntime\/Lambda+LocalServer.swift","function":"withLocalServer(host:port:invocationEndpoint:eventLoopGroup:logger:_:)","line":168} |
| switch level.uppercased() { | ||
| case "TRACE": return .trace | ||
| case "DEBUG": return .debug | ||
| case "INFO": return .info |
There was a problem hiding this comment.
Question: Probably not required but do we need to map "NOTICE" to .info?
This PR adds support for Structured Logging, as per the design document