Skip to content

Lambda timeout with Tracing 1.5.1 using async methods #659

Closed
@JonathanVerberne

Description

@JonathanVerberne

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

Metadata

Metadata

Assignees

Labels

area/tracingCore tracing utilitybugUnexpected, reproducible and unintended software behaviourreleasedFix or implementation already in main and released

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions