使用App Insights将相关ID添加到自动生成的遥测中 [英] Adding correlation id to automatically generated telemetry with App Insights

查看:71
本文介绍了使用App Insights将相关ID添加到自动生成的遥测中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Application Insights非常陌生,我正在考虑将其用于计划通过asp.net webapi实现的一组服务.我能够非常轻松地启动并运行基本遥测(在VS上的项目上单击鼠标右键,添加应用程序见解"),但是遇到了一个障碍.我计划在请求标头中设置一个相关ID,以用于对下游服务的呼叫,并且我希望使用相同的相关ID标记与一个外部呼叫相关的所有遥测.

I'm very new to Application Insights, and I'm thinking of using it for a set of services I plan on implementing with asp.net webapi. I was able to get the basic telemetry up and running very easily (right-clicking on a project on VS, Add Application Insights), but then I hit a block. I plan to have a correlation id set in the request headers for calls to downstream services, and I would like to tag all the telemetry related to one outside call with the same correlation id.

到目前为止,我发现有一种方法可以配置TelemetryInitializer,但是如果我理解正确,它会在访问请求之前运行,这意味着我无法检查是否存在相关ID我应该附上.

So far I've found that there is a way to configure a TelemetryInitializer, but if I understood correctly, this is run before I get to access the request, meaning I can't check if there is a correlation id that I should attach.

所以我想可能有两种方法可以解决此问题:1)如果我可以某种方式实际上在初始化程序之前访问请求标头,那显然可以解决问题,或者2)以某种方式获得TelemetryClient实例的持有权用于报告自动生成的遥测.

So I guess there might be 2 ways to solve this: 1) if I can somehow actually get access to the request headers before the initializer, that would obviously solver the problem, or 2) somehow get a hold of the TelemetryClient instance that is used to report the automatically generated telemetry.

当我当然可以控制TelemetryClient上设置的哪些属性时,也许最后的选择就是关闭所有自动填充并手动完成所有操作.但这会做很多工作,所以我更愿意找到其他解决方案.

Perhaps the last resort would be to turn off all of the automatic stuff and do all of it manually, when I could of course control what properties are set on the TelemetryClient. But this would be quite a lot more work, so I'd prefer to find some other solution.

推荐答案

您有权利说应该使用TelemetryInitializer.在任何遥测项目上调用Track方法时,将调用所有TelemetryInitializer.自动生成的请求遥测是在请求OnEnd上跟踪"的,那时您应该拥有所有自定义标头.

You were rights saying that you should use TelemetryInitializer. All TelemetryInitializers are called when Track method is called on any telemetry item. Autogenerated request telemetry is "tracked" on request OnEnd, you should have all your custom headers available for you at that time.

这篇关于使用App Insights将相关ID添加到自动生成的遥测中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆