Adding custom properties for each request in Application Insights metrics

后端 未结 5 1999
孤街浪徒
孤街浪徒 2020-11-29 03:42

I d\'like to add custom properties to metrics taken by Application Insights to each request of my app. For example, I want to add the user login and the ten

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 04:41

    As mentioned by Alan, you could implement the IContextInitializer interface to add custom properties to ALL telemetry sent by Application Insights. However, I would also suggest looking into the ITelemtryInitializer interface. It is very similar to the context initializer, but it is called for every piece of telemetry sent rather than only at the creation of a telemetry client. This seems more useful to me for logging property values that might change over the lifetime of your app such as user and tenant related info like you had mentioned.

    I hope that helps you out. Here is a blog post with an example of using the ITelemetryInitializer.

提交回复
热议问题