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
posta 2 anni fa782 visualizzazioni
2 Risposte
0
Risposta accettata

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
TECNICO DI SUPPORTO
con risposta 2 anni fa
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
con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande