dd-trace-dotnet icon indicating copy to clipboard operation
dd-trace-dotnet copied to clipboard

SetException on automatic spans not working

Open alex-gausman opened this issue 2 years ago • 1 comments

Describe the bug Exceptions raised from within an AWS Lambda handler are not captured in the automatically traced span.

** Steps to Reproduce **

In the screenshot below, the following code is executed. As you can see the automatic Lambda span doesn't have the exception set on the error metadata.

public async Task<APIGatewayProxyResponse> UpdateMarkupLayerSvgAsync(APIGatewayProxyRequest request, ILambdaContext context)
{
      throw new Exception($"Failed to update layer {layerId}");
}

Also tried the following which also doesn't seem to append the error metadata

public async Task<APIGatewayProxyResponse> UpdateMarkupLayerSvgAsync(APIGatewayProxyRequest request, ILambdaContext context)
{
    using (var scope = Tracer.Instance.ActiveScope)
    {
        try
        {
            throw new Exception($"Failed to update layer {layerId}");
        }
        catch (Exception ex)
        {
            scope.Span.SetException(ex);
            throw;
        }
    }
}

image

In the screenshot below, you can see that if I manually create a span within my handler code and explicitly SetException then the error metadata is set on the span.

using (var scope = Tracer.Instance.StartActive("UpdateMarkupLayerSvgAsync()"))
{
    try
    {
        throw new Exception($"Failed to update layer {layerId}");
    }
    catch (Exception ex)
    {
        scope.Span.SetException(ex);
        throw;
    }
}

image

Expected behavior Although, I can create new spans and SetException(), this results in two nearly identical spans. I would like to avoid the duplicate Lambda span and have the automatic tracing SetException() on the implicit span. This would allow allow me to not manually wrap every AWS Lambda handler with a try/catch.

Runtime environment (please complete the following information):

  • Instrumentation mode: Datadog Lambda extension layer
  • Tracer version:
    • arn:aws:lambda:us-east-1:464622532012:layer:dd-trace-dotnet:5
    • arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:28
  • OS: Amazon Linux 2
  • CLR: dotnet6

alex-gausman avatar Sep 12 '22 14:09 alex-gausman

Hi @alex-gausman, thank you for opening this issue. We are aware of the issue and are tracking it internally. We intend to address it very soon. I very much appreciate your clear description of how to reproduce and what you would like to see happen instead as it will be helpful as we implement this feature. We'll keep you updated here with our progress.

purple4reina avatar Sep 14 '22 16:09 purple4reina

Hi @pierotibou, just wanted to circle back and see if a bug fix for this is still on your backlog.

alex-gausman avatar May 05 '23 19:05 alex-gausman

Will do a release of the lambda layer soon.

joeyzhao2018 avatar Jan 22 '24 19:01 joeyzhao2018

This is fixed in v15 release. https://github.com/DataDog/dd-trace-dotnet-aws-lambda-layer/releases/tag/v15

joeyzhao2018 avatar Jan 25 '24 19:01 joeyzhao2018