How to link exceptions to requests in Application Insights on Azure?

前端 未结 4 600
没有蜡笔的小新
没有蜡笔的小新 2020-12-23 23:46

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:



        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 00:45

    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.

提交回复
热议问题