Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

.net - Why does AWS XRay require 'UseExceptionHandler' and 'UseStaticFiles' in AspNetCore?

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

  1. UseXRay after UseExceptionHandler in .NET Core 2.0.
  2. 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...