Environment
- ASP.NET WebAPI calling external client services.
XRay incoming trace applied in Global.asax via
AWSXRayASPNET.RegisterXRay(this, "CustomerAPI");
HttpClient instance hidden as private member in utility class, shared in a separate project with multiple WebAPI
HttpClient having delegating handler for Xray enable as follows:- (Ref: .NET HttpClient for outgoing XRay)
bool isXrayEnabled = false; bool.TryParse(Config["XRayEnable"], out isXrayEnabled); if (isXrayEnabled) { Logger.Info("Enabling XRay tracing with Http calls"); httpClient = new HttpClient(new HttpClientXRayTracingHandler(new HttpClientHandler())); } else { httpClient = new HttpClient(); Logger.Info("Disabling XRay tracing with Http calls"); }
Issue
While all APIs shows incoming XRay trace, the outgoing trace is not shown at all.
Instead, following error is shown in the XRay logs
Exception type: EntityNotAvailableException
Exception message: Entity doesn't exist in HTTPContext
at Amazon.XRay.Recorder.Core.Internal.Context.HybridContextContainer.InjectEntityInTraceContext()
at Amazon.XRay.Recorder.Core.AWSXRayRecorderImpl.AddHttpInformation(String key, Object value)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Amazon.XRay.Recorder.Core.AWSXRayRecorderImpl.AddHttpInformation(String key, Object value)
at Amazon.XRay.Recorder.Handlers.AspNet.AWSXRayASPNET.ProcessHTTPResponse(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)