aws-powertools / powertools-lambda-dotnet

Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.
https://docs.powertools.aws.dev/lambda/dotnet/
MIT No Attribution
152 stars 24 forks source link

Bug: Metrics failing to serialize LambdaContext on AOT runtime #612

Closed hjgraca closed 1 month ago

hjgraca commented 1 month ago

Expected Behaviour

When capturing cold starts Metrics write FunctionName to the EMF output, the FunctionName is retrieves from the LambdaContext passed to the handler.

StorageResolution should be the int representation of the enum and not the string representation, ie: Instead of"High" should be 1

Current Behaviour

In an AOT published Lambda when you have the following code

    [Metrics(Namespace = "ns", Service = "svc", CaptureColdStart = true)]
    public void HandleWithParamAndLambdaContext(string input, ILambdaContext context)
    {

    }

Should output

{
    "_aws": {
        "Timestamp": 1720714102216,
        "CloudWatchMetrics": [
            {
                "Namespace": "ns",
                "Metrics": [
                    {
                        "Name": "ColdStart",
                        "Unit": "Count"
                    }
                ],
                "Dimensions": [
                    [
                        "FunctionName"
                    ],
                    [
                        "Service"
                    ]
                ]
            }
        ]
    },
    "FunctionName": "pt-8",
    "Service": "svc",
    "ColdStart": 1
}

But instead was outputing

{
    "_aws": {
        "Timestamp": 1720714102216,
        "CloudWatchMetrics": [
            {
                "Namespace": "ns",
                "Metrics": [
                    {
                        "Name": "ColdStart",
                        "Unit": "Count"
                    }
                ],
                "Dimensions": [
                    [
                        "FunctionName"
                    ],
                    [
                        "Service"
                    ]
                ]
            }
        ]
    },
    "FunctionName": null, <--- should not be null
    "Service": "svc",
    "ColdStart": 1
}

Code snippet

In an AOT published Lambda have the following code

    [Metrics(Namespace = "ns", Service = "svc", CaptureColdStart = true)]
    public void HandleWithParamAndLambdaContext(string input, ILambdaContext context)
    {

    }

Possible Solution

No response

Steps to Reproduce

In an AOT published Lambda have the following code

    [Metrics(Namespace = "ns", Service = "svc", CaptureColdStart = true)]
    public void HandleWithParamAndLambdaContext(string input, ILambdaContext context)
    {

    }

Powertools for AWS Lambda (.NET) version

1.7.0

AWS Lambda function runtime

dotnet6

Debugging logs

No response