Skip to content

Conversation

@normj
Copy link
Member

@normj normj commented Sep 11, 2025

Issue #, if available:
#2121

Description of changes:
Amazon.Lambda.RuntimeSupport was lacking null protection if the message template was null and structured logging was enabled.

In addition Amazon.Lambda.Logging.AspNetCore was logging for the message template by looking at the log state for the key {OriginalFormat}. There are scenarios where there will be no {OriginalFormat} key. For example enabling HttpLogging. I updated Amazon.Lambda.Logging.AspNetCore to detect if there was no message template and if there was not one found use the passed in formatter using the state and exception to get a message template.

A later enhancement we should do is extend the RuntimeSupport logging API to pass in the other parameters from the message state that are now not going to be in the formatted message template and get them still included in the structured logging. That is a bigger scope then this null fix.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes NullReferenceException issues in AWS Lambda logging when message templates are null and structured logging is enabled. The fix adds null protection across multiple logging components and includes a fallback mechanism for scenarios where no message template is available.

  • Added null checks and fallback to empty string for message templates in RuntimeSupport
  • Enhanced AspNetCore logging to use formatter when OriginalFormat key is missing
  • Added comprehensive test coverage for null message template scenarios

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
JsonLogMessageFormatter.cs Added null coalescing operators to prevent NullReferenceException when MessageTemplate is null
ConsoleLoggerWriter.cs Added null protection for messageTemplate parameter
LambdaILogger.cs Added fallback to use formatter when messageTemplate is null
LogMessageFormatterTests.cs Added test cases for null message template scenarios
LoggingTests.cs Added test for logging without OriginalFormat key and fixed null exception handling
84836f7b-8e69-44a1-87dc-22971f426990.json Version bump configuration for both affected packages

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@afroz429 afroz429 requested a review from philasmar September 11, 2025 17:23
@normj normj changed the base branch from master to dev September 16, 2025 17:14
@normj normj merged commit 4b7587a into dev Sep 16, 2025
9 checks passed
@normj normj deleted the normj/fix-logging-null branch September 16, 2025 18:44
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