Skip to content

Add ability to customize structured logging serialization options#2383

Merged
normj merged 5 commits into
devfrom
normj/configure-structured-logging
May 18, 2026
Merged

Add ability to customize structured logging serialization options#2383
normj merged 5 commits into
devfrom
normj/configure-structured-logging

Conversation

@normj
Copy link
Copy Markdown
Member

@normj normj commented May 17, 2026

Issue #, if available:
#2350

Description

Adds the ability for users to customize the JsonSerializerOptions used by the Lambda runtime when serializing object parameters in structured log messages.

Changes

  • Amazon.Lambda.Core: Added StructuredLoggingOptions class with an OverrideSerializerOptions property allowing users to provide custom JsonSerializerOptions. Added LambdaLogger.ConfigureStructuredLogging(StructuredLoggingOptions) as the public entry point for configuring structured logging.
  • Amazon.Lambda.RuntimeSupport: Added ConfigureJsonLogMessageFormatterIsolated to bridge the callback from Amazon.Lambda.Core into the JsonLogMessageFormatter, translating between the Core and RuntimeSupport versions of StructuredLoggingOptions. The JsonLogMessageFormatter now accepts custom serializer options that override the defaults used when serializing {@property} values.

The design handles version mismatches between Amazon.Lambda.Core and Amazon.Lambda.RuntimeSupport:

  • A mirror StructuredLoggingOptions class in RuntimeSupport avoids a hard coupling to the Core version.
  • ConfigureJsonLogMessageFormatterIsolated isolates the type load so that an older Core (without StructuredLoggingOptions) gracefully falls back via TypeLoadException handling.
  • A placeholder mechanism in LambdaLogger ensures that if a user calls ConfigureStructuredLogging before the runtime has initialized, the options are buffered and forwarded once the runtime registers its callback.

Testing

  • Unit tests added in Amazon.Lambda.RuntimeSupport.UnitTests (LogMessageFormatterTests) verifying the full callback chain from LambdaLogger.ConfigureStructuredLogging through to JsonLogMessageFormatter, including custom naming policies, null options handling, and custom ignore conditions.
  • Unit tests added in Amazon.Lambda.Core.Tests (StructuredLoggingTests) verifying the SetConfigureStructuredLoggingAction callback mechanism, placeholder forwarding, and default state.
  • Manually confirmed that the changes in Amazon.Lambda.RuntimeSupport work correctly when deployed with an old version of Amazon.Lambda.Core that does not include the new StructuredLoggingOptions type.

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

@normj normj requested review from a team as code owners May 17, 2026 21:43
@normj normj requested review from GarrettBeatty and philasmar May 17, 2026 21:43
@normj normj marked this pull request as draft May 17, 2026 21:43
Copy link
Copy Markdown

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

Adds a public configuration hook in Amazon.Lambda.Core to let customers override the JsonSerializerOptions used for structured logging destructuring, and wires that through Amazon.Lambda.RuntimeSupport so JsonLogMessageFormatter can apply the override when serializing {@property} values.

Changes:

  • Introduces Amazon.Lambda.Core.StructuredLoggingOptions and LambdaLogger.ConfigureStructuredLogging(...) (preview) with a buffering/forwarding mechanism before runtime initialization.
  • Adds a RuntimeSupport “isolated” bridge to connect the Core callback into JsonLogMessageFormatter, handling version mismatch scenarios.
  • Adds unit tests in both Core and RuntimeSupport to validate the callback chain and serializer-option effects.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/LogMessageFormatterTests.cs Adds tests verifying serializer option overrides affect destructured JSON output.
Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/Amazon.Lambda.RuntimeSupport.UnitTests.csproj Suppresses CA2252 for preview API usage in tests.
Libraries/test/Amazon.Lambda.Core.Tests/StructuredLoggingTests.cs Adds Core tests for callback registration and default options state.
Libraries/test/Amazon.Lambda.Core.Tests/Amazon.Lambda.Core.Tests.csproj Suppresses CA2252 for preview API usage in tests.
Libraries/src/Amazon.Lambda.RuntimeSupport/Helpers/Logging/JsonLogMessageFormatter.cs Registers Core callback and applies override serializer options when destructuring.
Libraries/src/Amazon.Lambda.RuntimeSupport/Helpers/Logging/ConfigureJsonLogMessageFormatterIsolated.cs Bridges Core options into RuntimeSupport options, intended to isolate type-load/version mismatch behavior.
Libraries/src/Amazon.Lambda.Core/StructuredLoggingOptions.cs Adds the new options type surfaced to customers.
Libraries/src/Amazon.Lambda.Core/LambdaLogger.cs Adds preview configuration API and buffering/forwarding mechanism to integrate with RuntimeSupport.
.autover/changes/1d2619b4-c0e7-4fcd-81a6-7ef7dcf4e2e8.json Adds release notes entries for the new preview feature and RuntimeSupport integration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Libraries/src/Amazon.Lambda.Core/StructuredLoggingOptions.cs Outdated
Comment thread Libraries/src/Amazon.Lambda.Core/LambdaLogger.cs Outdated
Comment thread Libraries/src/Amazon.Lambda.Core/LambdaLogger.cs Outdated
Comment thread Libraries/test/Amazon.Lambda.Core.Tests/StructuredLoggingTests.cs Outdated
Comment thread .autover/changes/1d2619b4-c0e7-4fcd-81a6-7ef7dcf4e2e8.json Outdated
@normj normj marked this pull request as ready for review May 17, 2026 22:46
@GarrettBeatty
Copy link
Copy Markdown
Contributor

Manually confirmed that the changes in Amazon.Lambda.RuntimeSupport work correctly when deployed with an old version of Amazon.Lambda.Core that does not include the new StructuredLoggingOptions type.

just thinking for the future if we think its possible to have integration tests that does this scenario so we dont have to do this every time?

@normj normj merged commit fcad626 into dev May 18, 2026
5 checks passed
@normj normj deleted the normj/configure-structured-logging branch May 18, 2026 17:23
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.

4 participants