Skip to content

Commit 434add6

Browse files
authored
Merge pull request #649 from hjgraca/(docs)-update-logging-aot
chore: update logging aot docs
2 parents 335eef7 + 243db4d commit 434add6

File tree

15 files changed

+24
-30
lines changed

15 files changed

+24
-30
lines changed

docs/core/logging.md

+9-15
Original file line numberDiff line numberDiff line change
@@ -670,22 +670,19 @@ You can customize the structure (keys and values) of your log entries by impleme
670670

671671
## AOT Support
672672

673-
Logging utility supports native AOT serialization by default without any changes needed.
674-
675673
!!! info
676674

677-
In case you want to use the `LogEvent`, `Custom Log Formatter` features or serialize your own types when Logging events it is required
678-
that you do some changes in your Lambda `Main` method.
675+
If you want to use the `LogEvent`, `Custom Log Formatter` features, or serialize your own types when Logging events, you need to make changes in your Lambda `Main` method.
679676

680677
!!! info
681678

682-
Starting from version 1.6.0 it is required to update `Amazon.Lambda.Serialization.SystemTextJson` to `version 2.4.3` in your `csproj`.
679+
Starting from version 1.6.0, it is required to update the Amazon.Lambda.Serialization.SystemTextJson NuGet package to version 2.4.3 in your csproj.
683680

684681
### Configure
685682

686-
The change needed is to replace `SourceGeneratorLambdaJsonSerializer` with `PowertoolsSourceGeneratorSerializer`.
683+
Replace `SourceGeneratorLambdaJsonSerializer` with `PowertoolsSourceGeneratorSerializer`.
687684

688-
This change enables Powertools to construct an instance of JsonSerializerOptions that is used to customize the serialization and deserialization of the Lambda JSON events and your own types.
685+
This change enables Powertools to construct an instance of `JsonSerializerOptions` used to customize the serialization and deserialization of Lambda JSON events and your own types.
689686

690687
=== "Before"
691688

@@ -726,13 +723,11 @@ public partial class MyCustomJsonSerializerContext : JsonSerializerContext
726723
}
727724
```
728725

729-
When you change to `PowertoolsSourceGeneratorSerializer<MyCustomJsonSerializerContext>` we are
730-
combining your `JsonSerializerContext` types with Powertools `JsonSerializerContext`. This allows Powertools to serialize your types and Lambda events.
726+
When you update your code to use `PowertoolsSourceGeneratorSerializer<MyCustomJsonSerializerContext>`, we combine your `JsonSerializerContext` with Powertools' `JsonSerializerContext`. This allows Powertools to serialize your types and Lambda events.
731727

732728
### Custom Log Formatter
733729

734-
To be able to use a custom log formatter with AOT we need to pass an instance of ` ILogFormatter` to `PowertoolsSourceGeneratorSerializer`
735-
instead of using the static `Logger.UseFormatter` in the Function contructor.
730+
To use a custom log formatter with AOT, pass an instance of `ILogFormatter` to `PowertoolsSourceGeneratorSerializer` instead of using the static `Logger.UseFormatter` in the Function constructor as you do in non-AOT Lambdas.
736731

737732
=== "Function Main method"
738733

@@ -790,8 +785,7 @@ instead of using the static `Logger.UseFormatter` in the Function contructor.
790785
### Anonymous types
791786

792787
!!! note
793-
794-
Although we support anonymous type serialization by converting to a `Dictionary<string, object>`,
795-
this is not a best practice and is not recommendede when using native AOT.
796788

797-
Recommendation is to use concrete classes and add them to your `JsonSerializerContext`.
789+
While we support anonymous type serialization by converting to a `Dictionary<string, object>`, this is **not** a best practice and is **not recommended** when using native AOT.
790+
791+
We recommend using concrete classes and adding them to your `JsonSerializerContext`.

examples/BatchProcessing/src/HelloWorld/HelloWorld.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
9-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
9+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
1010
<PackageReference Include="AWS.Lambda.Powertools.BatchProcessing" Version="1.1.2" />
1111
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
1212
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />

examples/BatchProcessing/test/HelloWorld.Test/HelloWorld.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageReference Include="Amazon.Lambda.KinesisEvents" Version="2.2.0" />
99
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.2.0" />
1010
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="2.0.0" />
11-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
11+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
1212
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
1313
<PackageReference Include="AWSSDK.SQS" Version="3.7.300.54" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />

examples/Idempotency/src/HelloWorld/HelloWorld.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ItemGroup>
88
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
99
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
10-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
10+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
1111
<PackageReference Include="AWS.Lambda.Powertools.Idempotency" Version="1.2.2" />
1212
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
1313
</ItemGroup>

examples/Idempotency/test/HelloWorld.Test/HelloWorld.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
77
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="2.0.0" />
8-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
8+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
99
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1010
<PackageReference Include="xunit" Version="2.7.0" />
1111
<PackageReference Include="Testcontainers" Version="3.7.0" />

examples/Logging/src/HelloWorld/HelloWorld.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ItemGroup>
88
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
99
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
10-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
10+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
1111
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
1212
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
1313
</ItemGroup>

examples/Logging/test/HelloWorld.Test/HelloWorld.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
77
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="2.0.0" />
8-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
8+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
99
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1111
<PackageReference Include="NSubstitute" Version="5.1.0" />

examples/Metrics/src/HelloWorld/HelloWorld.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ItemGroup>
88
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
99
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
10-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
10+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
1111
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
1212
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.7.1" />
1313
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />

examples/Metrics/test/HelloWorld.Test/HelloWorld.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
77
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="2.0.0" />
8-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
8+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
99
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1111
<PackageReference Include="NSubstitute" Version="5.1.0" />

examples/Parameters/cfn/HelloWorld.Cfn/HelloWorld.Cfn.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88
<ItemGroup>
99
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
10-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
10+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
1111
</ItemGroup>
1212
<ItemGroup>
1313
<ProjectReference Include="..\..\src\HelloWorld\HelloWorld.csproj" />

examples/Parameters/src/HelloWorld/HelloWorld.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ItemGroup>
88
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
99
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
10-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
10+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
1111
<PackageReference Include="AWS.Lambda.Powertools.Parameters" Version="1.2.0" />
1212
</ItemGroup>
1313
</Project>

examples/Parameters/test/HelloWorld.Test/HelloWorld.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
77
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="2.0.0" />
8-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
8+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
99
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1010
<PackageReference Include="NSubstitute" Version="5.1.0" />
1111
<PackageReference Include="xunit" Version="2.7.0" />

examples/Tracing/src/HelloWorld/HelloWorld.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ItemGroup>
88
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
99
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
10-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
10+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
1111
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
1212
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.5.1" />
1313
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />

examples/Tracing/test/HelloWorld.Test/HelloWorld.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
77
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="2.0.0" />
8-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
8+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
99
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1111
<PackageReference Include="NSubstitute" Version="5.1.0" />

libraries/tests/AWS.Lambda.Powertools.Logging.Tests/Formatter/LogFormatterTest.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ public void Should_Log_CustomFormatter_When_Decorated()
203203
#if NET8_0_OR_GREATER
204204
consoleOut.Received(1).WriteLine(
205205
Arg.Is<string>(i =>
206-
i ==
207-
"{\"message\":\"test\",\"service\":\"my_service\",\"correlation_ids\":{\"aws_request_id\":\"requestId\"},\"lambda_function\":{\"name\":\"funtionName\",\"arn\":\"function::arn\",\"memory_limit_in_mb\":128,\"version\":\"version\",\"cold_start\":true},\"level\":\"Information\",\"timestamp\":\"2024-01-01T00:00:00.0000000\",\"logger\":{\"name\":\"AWS.Lambda.Powertools.Logging.Logger\",\"sample_rate\":0.2}}")
206+
i.Contains(
207+
"\"correlation_ids\":{\"aws_request_id\":\"requestId\"},\"lambda_function\":{\"name\":\"funtionName\",\"arn\":\"function::arn\",\"memory_limit_in_mb\":128,\"version\":\"version\",\"cold_start\":true},\"level\":\"Information\""))
208208
);
209209
#else
210210
consoleOut.Received(1).WriteLine(

0 commit comments

Comments
 (0)