aws / aws-xray-sdk-dotnet

The official AWS X-Ray SDK for .NET.
Apache License 2.0
109 stars 64 forks source link

DefaultExceptionSerializationStrategy throws System.NullReferenceException #252

Open kvattikuti opened 2 years ago

kvattikuti commented 2 years ago

AWSSDK.XRay Version="3.7.0.29" AWSXRayRecorder.Handlers.AwsSdk Version="2.8.3"

NullReferenceException: Exception: Object reference not set to an instance of an object.
at Amazon.XRay.Recorder.Core.Strategies.DefaultExceptionSerializationStrategy.<>c__DisplayClass14_0.<DescribeException>b__3(ExceptionDescriptor d)
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at Amazon.XRay.Recorder.Core.Strategies.DefaultExceptionSerializationStrategy.DescribeException(Exception e, IEnumerable`1 subsegments)
at Amazon.XRay.Recorder.Core.Internal.Entities.Entity.AddException(Exception e)
at Amazon.XRay.Recorder.Core.AWSXRayRecorderImpl.AddException(Exception ex)
at Ecova.DaaS.Aws.LambdaEntryPoints.HttpApi.HttpRestApiLogger.AddXrayAnnotations(IAWSXRayRecorder xrayRecorder, ApiGatewayProxyRequestWrapper requestWrapper, RequestAnnotations requestAnnotations, String partyMemberIdentifier, String awsRequestId, String correlationId, Exception exception, String errorString) in /src/Aws/Ecova.DaaS.Aws.LambdaEntryPoints/HttpApi/HttpRestApiLogger.cs:line 103
at Ecova.DaaS.Aws.LambdaEntryPoints.HttpApi.HttpRestApiLogger.LogResponse(ILogger logger, IAWSXRayRecorder xrayRecorder, ApiGatewayProxyRequestWrapper requestWrapper, String partyMemberIdentifier, RequestAnnotations requestAnnotations, Int32 httpStatusCode, Int64 timeTakenToCompleteRequest, String awsRequestId, String correlationId, Exception exception, String responseBody) in /src/Aws/Ecova.DaaS.Aws.LambdaEntryPoints/HttpApi/HttpRestApiLogger.cs:line 52
at Ecova.DaaS.Aws.LambdaEntryPoints.HttpApi.HttpRestApi.FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context) in /src/Aws/Ecova.DaaS.Aws.LambdaEntryPoints/HttpApi/HttpRestApi.cs:line 145

This happens when we IAWSXRayRecorder.AddException() to X-ray recorder. It happens intermittently.

Not sure how much of help this is but here is the stacktrace of the exception we are trying to add:


Exception: 1 validation error detected: Value at 'records.1.member.data' failed to satisfy constraint: Member must have length less than or equal to 1048576
at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)
at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception)
at Amazon.Runtime.Internal.ExceptionHandler`1.HandleAsync(IExecutionContext executionContext, Exception exception)
at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.XRay.Recorder.Handlers.AwsSdk.Internal.XRayPipelineHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
at Ecova.DaaS.DependencyInjection.Aws.Implementations.KinesisBatchSender`1.SendBatchHelperInner(List`1 requests) in /src/Aws/Ecova.DaaS.DependencyInjection.Aws/Implementations/KinesisBatchSender.cs:line 202
at Ecova.DaaS.DependencyInjection.Aws.Implementations.KinesisBatchSender`1.<>c__DisplayClass22_0.<<SendBatchHelper>b__0>d.MoveNext() in /src/Aws/Ecova.DaaS.DependencyInjection.Aws/Implementations/KinesisBatchSender.cs:line 174
--- End of stack trace from previous location where exception was thrown ---
at Polly.AsyncPolicy.<>c__DisplayClass40_0.<<ImplementationAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func`3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates`1 shouldRetryResultPredicates, Func`5 onRetryAsync, Int32 permittedRetryCount, IEnumerable`1 sleepDurationsEnumerable, Func`4 sleepDurationProvider, Boolean continueOnCapturedContext)
Inner-Exception: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)

See related issue #96 which was closed without fixing it because of inactivity.

srprash commented 2 years ago

Hi @kvattikuti Apologies that the previously related issue was closed pre-maturely. I am trying to reproduce this issue but since it seems intermittent, I haven't been successful yet.

From the stack trace of your exception, I am not able to determine if this is happening only for a specific type of exception from the AWS SDK client (for kinesis?). Can you provide a snippet of code showing how you're calling the AWS service via the client, and what is the exception you are getting which in turn is leading to the NullReferenceException in the X-Ray SDK? Thanks!

jon-armen commented 2 years ago

@srprash , @kvattikuti - This looks like the exact same exception I was getting in #209 which was fixed by #210. That is now released in AWSXRayRecorder.Handlers.AwsSdk v2.9.0

NathanielRN commented 2 years ago

@kvattikuti could you please try importing the latest release and verify if that fix worked for you? If it does, can you close the issue? Thanks! 🙂