I'm following Amazon's documentation to enable XRay in one of our Lambda APIs under Api Gateway, and I noticed it tells you to add 3 middlewares to the configuration:
UseExceptionHandler
UseXRay
UseStaticFiles
The first and third middlewares are native AspNet integrations, while the second is the actual Amazon XRay implementation. The documentation never states why the other 2 are needed. Instead, it has this to say about ordering:
Always call UseXRay after UseExceptionHandler to record exceptions. If you use other middleware, enable it after you call UseXRay.
It is not clear to me if the exception handler is even necessary, or if they just mean that, "if you happen to have it, add XRay after it".
The documentation says nothing about UseStaticFiles
.
I want to know why Amazon is making me add these other middlewares before proceeding with the change. If they really need to be added, there must be a documented reason for doing so.
In particular, this is giving me a few problems with UseExceptionHandler
, which doesn't appear to be working correctly with an OData-enabled API which is my current case.
It's not necessary to use exception or static files handlers when using X-Ray middleware. But if you have an exception handler in your application already and you want to record the inner exception stack, make sure to call:
UseXRay
after UseExceptionHandler
in .NET Core 2.0.UseXRay
in the beginning of http pipeline in .NET Core 2.1 and above.See: https://github.com/aws/aws-xray-sdk-dotnet/tree/master#aspnet-core-framework-net-core--nuget