Allow custom `JsonSerializerOptions` (and converters) in `JsonLogMessageFormatter`
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- aws, csharp
- Domain
- backend, observability-sre
Research direction
Read Libraries/src/Amazon.Lambda.RuntimeSupport/Helpers/Logging/JsonLogMessageFormatter.cs and the related structured-logging context in issue #1747 first. Decide and implement one supported options-injection API; done means custom converters affect destructured output while the existing default options and behavior remain unchanged.
Written by the indexing model from the issue text.
Description
Describe the feature
The JsonLogMessageFormatter introduced in Amazon.Lambda.RuntimeSupport 1.12.0 hardcodes its JsonSerializerOptions in the parameterless constructor:
// JsonLogMessageFormatter.cs
private readonly JsonSerializerOptions _jsonSerializationOptions;
public JsonLogMessageFormatter()
{
_jsonSerializationOptions = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
WriteIndented = false
};
}
There is currently no way for a customer to inject custom JsonSerializerOptions or register custom JsonConverters. The only documented customization path is to apply [JsonConverter(...)] attributes individually on every property of every type that may end up in a {@param} destructured log call.
Use Case
Many .NET codebases use third-party value types that have no public properties (so JsonSerializer.Serialize without converters produces empty {}) but provide official JsonConverters in companion packages. Examples:
- NodaTime (
Instant,LocalDate,LocalDateTime,Duration,Period...) - converters inNodaTime.Serialization.SystemTextJson - NetTopologySuite geographic types - converters in
NetTopologySuite.IO.GeoJSON4STJ - Domain primitive / value object libraries like Vogen, StronglyTypedId - generated converters
In our codebase, NodaTime is used pervasively across business entities and SQS messages. Whenever we want to use the new {@Object} destructuring syntax to log a complex object, NodaTime properties serialize as empty objects, which silently loses data:
// Current output for `_logger.LogInformation("Email queued {@Message}", sqsMessage)`:
{
"timestamp": "2026-04-29T10:00:00.000Z",
"level": "Information",
"requestId": "...",
"message": "Email queued {@Message}",
"Message": {
"To": "alice@example.com",
"EventDate": {}, // ← lost: should be "2026-04-29T10:00:00Z"
"TemplateKey": "ACCOUNT_CREATED"
}
}
Annotating each property of every entity with a custom [JsonConverter] attribute is invasive, mixes serialization concerns with persistence/domain code, and is fragile (easy to forget on a new property - silent data loss).
Proposed Solution
Expose a constructor overload (or a factory hook) that accepts a custom JsonSerializerOptions instance. Three possible levels of API, in order of preference:
- Minimal: add a static
JsonLogMessageFormatter.ConfigureOptions(Action<JsonSerializerOptions>)method that the runtime applies after creating its default options. Optionally also support a declarative form via anAWS_LAMBDA_LOG_FORMATTER_OPTIONS_CONFIGURATORenvironment variable pointing to aType::Method, mirroring how[LambdaSerializer]attribute already lets users plug a custom serializer. - DI-based: allow consumers to register a
JsonSerializerOptions(or anIJsonSerializerOptionsProvider) in DI; the runtime support reads it on first log call. - Subclass-friendly: change
_jsonSerializationOptionstoprotected, add a virtualCreateJsonSerializerOptions()method, allow subclassingJsonLogMessageFormatterand selecting it via env var or DI.
Option 1 is the least invasive and matches how Amazon.Lambda.Serialization.SystemTextJson.SourceGeneratorLambdaJsonSerializer<T> already lets customers swap the serializer.
Other Information
Alternatives considered
- Annotating every domain property with
[JsonConverter]: works but invasive, fragile, mixes concerns. - Avoiding
{@Object}on objects containing custom types: works but defeats much of the structured-logging value. - Pre-serializing in user code with
JsonSerializer.Serialize(value, customOptions)then logging as a string: loses the "queryable hierarchical fields" benefit on the CloudWatch Logs Insights side. - Switching to a third-party logger (Serilog, NLog): works but requires customers to leave the AWS-recommended path and re-implement
requestId/traceIdenrichment.
Additional context
- Affected source file:
Libraries/src/Amazon.Lambda.RuntimeSupport/Helpers/Logging/JsonLogMessageFormatter.cs - Related issue: #1747 (closed, parent feature for structured logging)
- Documentation: AWS .NET dev blog post on structured logging doesn't mention this customization path.
Adding this hook would close a real gap for any codebase using third-party value types with companion JsonConverters, without affecting the default behavior.
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
AWS .NET SDK and/or Package version used
Amazon.Lambda.RuntimeSupport: 1.12.0+ (provided by the managed runtime; source inspected onmasterbranch as of issue submission)Amazon.Lambda.Core: 2.4.0+Amazon.Lambda.Logging.AspNetCore: 5.0.0+
Targeted .NET Platform
.NET 10 (net10.0), running on the AWS Lambda managed dotnet10 runtime. The same limitation applies on net8.0 / dotnet8.
Operating System and version
AWS Lambda managed runtime (Amazon Linux 2023, x86_64). Reproducible identically on arm64. Local repro on Windows 11 / .NET 10 SDK.
- Dominant language
- C#
- Stars
- 1.7k
- Forks
- 503
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 21
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aws/aws-lambda-dotnet
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
aws/aws-lambda-dotnet#2571 · 1 comment ·
-
bug module/aspnetcore-support p2 queued
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
aws/aws-lambda-dotnet#1123 · 4 comments · 1 reaction ·
-
feature-request
Difficulty 4/5 3-5 days Newbie friendliness 68/100
aws/aws-lambda-dotnet#2572 · 1 comment ·
-
feature-request needs-triage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
aws/aws-lambda-dotnet#2551 · 1 comment ·
-
feature-request needs-review
Difficulty 5/5 Over a week Newbie friendliness 35/100
aws/aws-lambda-dotnet#2519 ·
All issues in aws/aws-lambda-dotnet
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·