App Insights TelemetryInitializer中的异常处理

时间:2017-10-23 16:23:16

标签: azure azure-application-insights

我使用Initialize ITelemetryInitializer方法向我的AppInsights事件添加了多个自定义属性。其中一些是从数据库或其他可能失败的源中检索的。问题是,开发人员是否有任何关于try-catch方法中是否应包含Initialize条款的官方建议?

根据我观察到的情况,在方法中抛出异常并不会阻止遥测出现,尽管无法按预期看到自定义属性。我可以依靠这种行为吗?它是否以某种方式影响性能,我不会手动处理异常并让AppInsights'代码处理它们呢?

1 个答案:

答案 0 :(得分:0)

It depends, doesn't it. If the telemetry initializer adds multiple custom properties and the first one in line fails with an exception, do you want to try to add the others. If so, put a try/catch around each custom property.

If it is just a single property, or all should not be added as soon as the first one fails then you could choose not to handle the exception. In my opinion however, I would want to have control over the exception propagation and choose for handling them myself. (and maybe ignore them with an empty catch, depending on the situation)

Ignoring them completely may give troubles in the future when the SDK for example is altered to not send the telemetry to App Insights when a telemetry initializer fails with an unhandled exception. At least if you decide to go this route try take a peek in the source code of the SDK to see what happens with the unhandled exception.