dd-trace-dotnet
dd-trace-dotnet copied to clipboard
SetException on automatic spans not working
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;
}
}
}
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;
}
}
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
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.
Hi @pierotibou, just wanted to circle back and see if a bug fix for this is still on your backlog.
Will do a release of the lambda layer soon.
This is fixed in v15 release. https://github.com/DataDog/dd-trace-dotnet-aws-lambda-layer/releases/tag/v15