We are using Owin on Azure for a REST service, and have to report to Application Insights directly. We want to log exceptions and requests. Right now we have this:
For my current client, we're not yet OWIN-ed up.
I registered a DelegatingHandler with WebAPI that sticks the current request into the thread's SynchronizationContext via CallContext.LogicalSetData and removes it after the request is complete.
In my existing logging system, which had to be retro-fitted with the Application Insights stuff, I then grab the request from the thread via CallContext.LogicalSetData and set about getting the HttpContext which is placed into the request properties by the framework, then from the HttpContext.Items, I get the RequestTelemetry instance.
Ultimately, this is all needed because I can't get access to the request or action or anything from the IoC container that's newing-up the services.
Eventually we might rewrite some of this to allow improved creation and flowing of an OperationContext or InstrumentationContext style object down the stack and get rid of the handler and CallContext funny business.