-
Notifications
You must be signed in to change notification settings - Fork 26
Bug: AoT does not work with metrics or logger #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@Euclidite I can reproduce the error you are getting when I have the <!-- Generate Native AOT image during publishing to improve cold start time. -->
<PublishAot>true</PublishAot>
<!-- StripSymbols tells the compiler to strip debugging symbols from the final executable if we're on Linux and put them into their own file.
This will greatly reduce the final executable's size.-->
<StripSymbols>true</StripSymbols>
<!-- TrimMode partial will only trim assemblies marked as trimmable. To reduce package size make all assemblies trimmable and set TrimMode to full.
If there are trim warnings during build, you can hit errors at runtime.-->
<TrimMode>partial</TrimMode> One explanation for the differences between both those properties dotnet/runtime#97288 (comment) |
The config I was using was to slowly get to full AoT because using true forces it to use a docker build, so I wanted to chip away at a single problem at a time 😉 Regardless, I tested out with your suggested changes, but I still get the same error message. |
Indeed local dev docker is required, I usually use a dev box ie: an ec2 AL2023 and develop/piblish from there, no docker needed 😀 |
Oh! I might look into setting that up once we iron out some of our build pipelines - thanks for the tip! And yes:
|
I can't seem to replicate the issue, here is my code: Function.csusing Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using AWS.Lambda.Powertools.Logging;
using AWS.Lambda.Powertools.Logging.Serializers;
using System.Text.Json.Serialization;
namespace pt_aot_test;
public class Function
{
private static async Task Main()
{
await LambdaBootstrapBuilder.Create<SubmitFeedbackRequest>(
FunctionHandlerAsync,
new PowertoolsSourceGeneratorSerializer<LambdaFunctionJsonContext>())
.Build()
.RunAsync();
}
[Logging]
public static async Task FunctionHandlerAsync(SubmitFeedbackRequest request, ILambdaContext context)
{
Logger.LogInformation("Starting up!");
}
}
public class SubmitFeedbackRequest
{
public int Id { get; set; }
}
[JsonSerializable(typeof(SubmitFeedbackRequest))]
public partial class LambdaFunctionJsonContext : JsonSerializerContext { } csproj<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AWSProjectType>Lambda</AWSProjectType>
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<!-- Generate Native AOT image during publishing to improve cold start time. -->
<PublishAot>true</PublishAot>
<!-- StripSymbols tells the compiler to strip debugging symbols from the final executable if we're on Linux and put them into their own file.
This will greatly reduce the final executable's size.-->
<StripSymbols>true</StripSymbols>
<!-- TrimMode partial will only trim assemblies marked as trimmable. To reduce package size make all assemblies trimmable and set TrimMode to full.
If there are trim warnings during build, you can hit errors at runtime.-->
<TrimMode>partial</TrimMode>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.1" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.11.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.3.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.1" />
</ItemGroup>
</Project> aws-lambda-tools-defaults.json (don't think it matters) "profile": "",
"region": "eu-west-1",
"configuration": "Release",
"function-runtime": "dotnet8",
"function-memory-size": 512,
"function-timeout": 5,
"function-handler": "pt-aot-test",
"function-architecture": "x86_64",
"framework": "net8.0",
"msbuild-parameters": "--self-contained true" |
I've compared the values, and I have them set identically. I retested just in case and still get the same error (or well slightly different, but I think that's simply because of the AoT)
For reference, here's the public class SubmitFeedbackRequest
{
[Required(AllowEmptyStrings = false)]
public required string SessionId { get; set; }
[MinLength(1)] // This logs an AOT warning, but its safe to ignore and will be fixed in a future release
public required IEnumerable<int> FeedbackType { get; set; }
[Range(1, int.MaxValue)]
public required int ReferenceId { get; set; }
[EmailAddress]
public required string UserEmail { get; set; }
} I do see these warnings in the build:
|
Thanks for providing more details @Euclidite . Function.csusing Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using AWS.Lambda.Powertools.Logging;
using AWS.Lambda.Powertools.Logging.Serializers;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace pt_aot_test;
public class Function
{
private static async Task Main()
{
await LambdaBootstrapBuilder.Create<SubmitFeedbackRequest>(
FunctionHandlerAsync,
new PowertoolsSourceGeneratorSerializer<LambdaFunctionJsonContext>())
.Build()
.RunAsync();
}
[Logging]
public static async Task FunctionHandlerAsync(SubmitFeedbackRequest request, ILambdaContext context)
{
Logger.LogInformation("Starting up!");
Logger.LogInformation(request);
}
}
public class SubmitFeedbackRequest
{
[Required(AllowEmptyStrings = false)]
public required string SessionId { get; set; }
[MinLength(1)] // This logs an AOT warning, but its safe to ignore and will be fixed in a future release
public required IEnumerable<int> FeedbackType { get; set; }
[Range(1, int.MaxValue)]
public required int ReferenceId { get; set; }
[EmailAddress]
public required string UserEmail { get; set; }
}
[JsonSerializable(typeof(SubmitFeedbackRequest))]
public partial class LambdaFunctionJsonContext : JsonSerializerContext { } Request{
"SessionId": "123",
"FeedbackType": [1,2],
"ReferenceId": 1,
"UserEmail": "[email protected]"
} Response{
"coldStart": true,
"xrayTraceId": "1-6708d42c-7547436656f7808d4abaafd9",
"functionName": "pt-aot-test",
"functionVersion": "$LATEST",
"functionMemorySize": 512,
"functionArn": "-",
"functionRequestId": "7ddfcf41-436e-45c7-bcec-f56cc530f469",
"timestamp": "2024-10-11T07:30:52.9777292Z",
"level": "Information",
"service": "henrique_service",
"name": "AWS.Lambda.Powertools.Logging.Logger",
"message": "Starting up!"
}
{
"coldStart": true,
"xrayTraceId": "1-6708d42c-7547436656f7808d4abaafd9",
"functionName": "pt-aot-test",
"functionVersion": "$LATEST",
"functionMemorySize": 512,
"functionArn": "-",
"functionRequestId": "7ddfcf41-436e-45c7-bcec-f56cc530f469",
"timestamp": "2024-10-11T07:30:52.9778246Z",
"level": "Information",
"service": "henrique_service",
"name": "AWS.Lambda.Powertools.Logging.Logger",
"message": {
"sessionId": "123",
"feedbackType": [
1,
2
],
"referenceId": 1,
"userEmail": "[email protected]"
}
}
|
If you want we can have a chat to go over this issue, just send me an email [email protected], or reach out on our discord |
@hjgraca apologies for the delay - I'm following up on a few things from my end & then I'll be able to retest this issue again (hopefully in a day or so). Thank you! |
@Euclidite if you need we can have a call to see what is failing? |
@Euclidite could not replicate. closing this for now, feel free to reach out and reopen the issue if you still find this bug. |
Expected Behaviour
Logger should work with AoT trimming enabled.
Current Behaviour
The following exception is thrown
Code snippet
Here are the relevant lines of what I have in my csproj file (Let me know if you need more context):
Here's how I've been able to minimally reproduce this issue:
For reference, here are my package versions:

Possible Solution
No response
Steps to Reproduce
See code snippet.
Powertools for AWS Lambda (.NET) version
latest
AWS Lambda function runtime
dotnet8 (AOT)
Debugging logs
No response
The text was updated successfully, but these errors were encountered: