How to solve "Entity doesn't exist in callcontext" exception in .Net console/library applications

0

Hi guys,

I am trying to add AWS X-Ray to our solution which includes S3, Lambda and DynamoDB services, but I am struggling with the exception "Entity doesn't exist in callcontext".

Normally, I would need the X-Ray service in a library project started via WCF webservice file (.svc), but in order to break down the problem I tried it in a simple console application having following minimum sample code and exactly the same error occurs:

private static void Main(string[] args)
{
    AWSSDKHandler.RegisterXRayForAllServices();

    var lambdaClient = new AmazonLambdaClient(awsCredentials, regionEndpoint);
    lambdaClient.Invoke(new InvokeRequest { ... });
}

When disabling line RegisterXRayForAllServices lambda request is working, when enabling the line, following exception is thrown when invoking the lambda request:

   at Amazon.XRay.Recorder.Core.Internal.Context.CallContextContainer.GetEntity()
   at Amazon.XRay.Recorder.Handlers.AwsSdk.Internal.XRayPipelineHandler.ProcessBeginRequest(IExecutionContext executionContext)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Amazon.XRay.Recorder.Handlers.AwsSdk.Internal.XRayPipelineHandler.ProcessBeginRequest(IExecutionContext executionContext)
   at Amazon.XRay.Recorder.Handlers.AwsSdk.Internal.XRayPipelineHandler.InvokeSync(IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext executionContext) in D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\CallbackHandler.cs:line 46
   at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeSync(IExecutionContext executionContext) in D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\ErrorCallbackHandler.cs:line 44
   at Amazon.Runtime.Internal.MetricsHandler.InvokeSync(IExecutionContext executionContext) in D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\MetricsHandler.cs:line 40
   at Amazon.Runtime.Internal.RuntimePipeline.InvokeSync(IExecutionContext executionContext) in D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\RuntimePipeline.cs:line 136
   at Amazon.Runtime.AmazonServiceClient.Invoke[TResponse](AmazonWebServiceRequest request, InvokeOptionsBase options) in D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\AmazonServiceClient.cs:line 206
   at Program.Main(String[] args) in Program.cs:line 42

Versions in use:

  • .Net Framework 4.7.2
  • Nuget AWSDDK.Lambda 3.7.13.16
  • Nuget AWSXRayRecoder: 2.10.1

In other projects without AWS services I do not have problems with RegisterXRay(this, "Program") and adding own segments and custom endpoints behaviors for WCF services, but here I would need some help, how to correctly setup the XRay recorder for AWS services. Is there anything additionally required in App.config/Web.config?

Thank you and BR

Fabian

Fabian
질문됨 2년 전782회 조회
2개 답변
0
수락된 답변

Hello,

Thank you for reaching out to us.

Using AWSSDKHandler.RegisterXRayForAllServices() will instrument all the AWS SDK clients in the user application. This means that the X-Ray SDK will create a Subsegment for every request made by these clients.

In X-Ray SDK, a subsegment can only be created if there is a parent Segment or Subsegment already open, which I don't see in the provided code example.

Can you try creating a segment and see if the issue still exists? The updated code would look like this:

private static void Main(string[] args)

{

AWSSDKHandler.RegisterXRayForAllServices();
AWSXRayRecorder.Instance.BeginSegment("MainSegment");
var lambdaClient = new AmazonLambdaClient(awsCredentials, regionEndpoint);
lambdaClient.Invoke(new InvokeRequest { ... });
AWSXRayRecorder.Instance.EndSegment();

}

AWS
지원 엔지니어
답변함 2년 전
0

Hi, I was not aware of the fact, that AWS services are added as Subsegments and starting with an own custom Segment will fix the issue. After adding an own segment, everything works fine! Thank you!

Fabian
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠