Skip to content
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

Lambda timeout with Tracing 1.5.1 using async methods #659

Closed
JonathanVerberne opened this issue Oct 3, 2024 · 7 comments · Fixed by #660
Closed

Lambda timeout with Tracing 1.5.1 using async methods #659

JonathanVerberne opened this issue Oct 3, 2024 · 7 comments · Fixed by #660
Assignees
Labels
area/tracing Core tracing utility bug Unexpected, reproducible and unintended software behaviour released Fix or implementation already in main and released

Comments

@JonathanVerberne
Copy link

Expected Behaviour

I've recently updated my Powertools tracing package from 1.4.2 to 1.5.1, since doing this I've noticed my lambda is timing out which was not the case when using 1.4.2.

I've noticed the issue is when using 1.5.1 any method that is called must have the [Tracing] attribute on top of the method, then it will not timeout, but this is not the same for version 1.4.2 if the [Tracing] attribute on the method is missing it will not cause the lambda to timeout. See code snippet below.

Current Behaviour

This is the output when testing my lambda in the AWS lambda test console. The lambda executes but does not end once it's finished executing the code, it only ends once it hits the Lambda timeout that's configured and in this case it's 30 seconds.

image

Code snippet

public class Functions
{
    private readonly ILogger<Functions> _logger;    
    private readonly HttpClient? _httpClient;

    public Functions(ILogger<Functions> logger)
    {
        Tracing.RegisterForAllServices();
        
        _logger = logger;
        
        _httpClient = new HttpClient();
    }
        
    [LambdaFunction]
    [Tracing]
    public async Task HandlerAsync(ILambdaContext context)
    {        
        await GetCallingIp();
    }

    public async Task<string?> GetCallingIp()
    {
        if (_httpClient == null) return "0.0.0.0";
        _httpClient.DefaultRequestHeaders.Accept.Clear();
        _httpClient.DefaultRequestHeaders.Add("User-Agent", "AWS Lambda .Net Client");

        try
        {
            _logger.LogInformation("Calling Check IP API");

            var response = await _httpClient.GetStringAsync("https://checkip.amazonaws.com/");
            var ip = response.Replace("\n", "");

            _logger.LogInformation($"API response returned {ip}");

            return ip;
        }
        catch (Exception)
        {
            throw;
        }
    }
}

Possible Solution

No response

Steps to Reproduce

The code snipped above works using version 1.4.2 but will timeout when using 1.5.1 - unless you add the [Tracing] attribute above the public async Task<string?> GetCallingIp().

Works with 1.4.2 (not with 1.5.1)
public async Task<string?> GetCallingIp()

Works with 1.5.1 - when [Tracing] added.
[Tracing]
public async Task<string?> GetCallingIp()

Powertools for AWS Lambda (.NET) version

latest

AWS Lambda function runtime

dotnet8

Debugging logs

{
  "errorType": "Sandbox.Timedout",
  "errorMessage": "RequestId: d16d6980-534b-47a3-987b-8b717df2bdce Error: Task timed out after 30.00 seconds"
}

START RequestId: d16d6980-534b-47a3-987b-8b717df2bdce Version: $LATEST
info: Annotations.Framework.Lambda.Prototype.Functions[0]
      Calling Check IP API
info: Annotations.Framework.Lambda.Prototype.Functions[0]
      API response returned 52.65.178.98
END RequestId: d16d6980-534b-47a3-987b-8b717df2bdce
REPORT RequestId: d16d6980-534b-47a3-987b-8b717df2bdce	Duration: 30000.00 ms	Billed Duration: 30000 ms	Memory Size: 128 MB	Max Memory Used: 96 MB	Init Duration: 330.59 ms	Status: timeout
XRAY TraceId: 1-66fe2f1d-59eedc543b26719255572c9c	SegmentId: 32442b50edce1961	Sampled: true
@JonathanVerberne JonathanVerberne added bug Unexpected, reproducible and unintended software behaviour triage Pending triage from maintainers labels Oct 3, 2024
Copy link

boring-cyborg bot commented Oct 3, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #dotnet channel on our Powertools for AWS Lambda Discord: Invite link

@hjgraca
Copy link
Contributor

hjgraca commented Oct 3, 2024

Hi @JonathanVerberne thanks for raising the issue, I am taking a look at this now and will try reproduce the behaviour. Will update soon.

@hjgraca
Copy link
Contributor

hjgraca commented Oct 3, 2024

Issue reproducible. Working on a fix

@hjgraca hjgraca added area/tracing Core tracing utility and removed triage Pending triage from maintainers labels Oct 3, 2024
@hjgraca hjgraca moved this to 🏗 In progress in Powertools for AWS Lambda (.NET) Oct 3, 2024
@hjgraca
Copy link
Contributor

hjgraca commented Oct 4, 2024

@JonathanVerberne
Fix #660 , will be release next Tuesday.
Many thanks for reporting the issue and using Powertools!

@hjgraca hjgraca self-assigned this Oct 4, 2024
@hjgraca hjgraca moved this from 🏗 In progress to 👀 In review in Powertools for AWS Lambda (.NET) Oct 4, 2024
@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Oct 5, 2024
@JonathanVerberne
Copy link
Author

That's fantastic... thank you @hjgraca !

@hjgraca
Copy link
Contributor

hjgraca commented Oct 8, 2024

Release 1.15
Tracing 1.5.2

@hjgraca hjgraca closed this as completed Oct 8, 2024
@hjgraca hjgraca added released Fix or implementation already in main and released and removed pending-release Fix or implementation already in dev waiting to be released labels Oct 8, 2024
@hjgraca hjgraca linked a pull request Oct 8, 2024 that will close this issue
7 tasks
@hjgraca
Copy link
Contributor

hjgraca commented Oct 8, 2024

@JonathanVerberne version 1.5.2 now available on NuGet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tracing Core tracing utility bug Unexpected, reproducible and unintended software behaviour released Fix or implementation already in main and released
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants