I would like to add a tag to the System.Diagnostics.Activity object for each incoming ASP.NET Request, as soon as the request-handling starts. Is there a way I can access the ActivitySource for the Request Pipeline, and add a listener to it?
Currently I'm thinking of using a Pipeline middleware, but there has to be a more lightweight way. Especially one where other developers can't add any other middleware handlers before this one. Any ideas?
Looks like you can add it via DI at startup. The Key thing is the name of the
ActivitySource
. I couldn't find it in any documentation. I had to trawl through the aspnetcore code, and it looks like registers an empty name ActivitySource for theDiagnosticListener
.In any case ...
Add the following to
Configure(...)
:That should be it.