Add ability to customize structured logging serialization options#2383
Conversation
There was a problem hiding this comment.
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.StructuredLoggingOptionsandLambdaLogger.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.
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? |
Issue #, if available:
#2350
Description
Adds the ability for users to customize the
JsonSerializerOptionsused by the Lambda runtime when serializing object parameters in structured log messages.Changes
StructuredLoggingOptionsclass with anOverrideSerializerOptionsproperty allowing users to provide customJsonSerializerOptions. AddedLambdaLogger.ConfigureStructuredLogging(StructuredLoggingOptions)as the public entry point for configuring structured logging.ConfigureJsonLogMessageFormatterIsolatedto bridge the callback fromAmazon.Lambda.Coreinto theJsonLogMessageFormatter, translating between the Core and RuntimeSupport versions ofStructuredLoggingOptions. TheJsonLogMessageFormatternow 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:
StructuredLoggingOptionsclass in RuntimeSupport avoids a hard coupling to the Core version.ConfigureJsonLogMessageFormatterIsolatedisolates the type load so that an older Core (withoutStructuredLoggingOptions) gracefully falls back viaTypeLoadExceptionhandling.LambdaLoggerensures that if a user callsConfigureStructuredLoggingbefore the runtime has initialized, the options are buffered and forwarded once the runtime registers its callback.Testing
Amazon.Lambda.RuntimeSupport.UnitTests(LogMessageFormatterTests) verifying the full callback chain fromLambdaLogger.ConfigureStructuredLoggingthrough toJsonLogMessageFormatter, including custom naming policies, null options handling, and custom ignore conditions.Amazon.Lambda.Core.Tests(StructuredLoggingTests) verifying theSetConfigureStructuredLoggingActioncallback mechanism, placeholder forwarding, and default state.StructuredLoggingOptionstype.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.