我们有一个 aspnetcore 项目,其中包含几个 Azure Functions 和一个依赖于 Redis 的 API。
使用code similar to this article我们已经将 Redis 调用跟踪到 Application Insights(很棒),但是它们记录到 Application Insights 实例而不是调用它们的系统,例如API(请参阅下面图表的屏幕截图)。
我们在启动中有 services.AddApplicationInsightsTelemetry();
。
我们是否需要设置一些东西来关联父容器应用程序和依赖项?
我们的跟踪如下所示:
_telemetryClient.TrackDependency(_telemetryType, _telemetryTarget, method, key, startTime, elapsed, string.Empty, true);
最佳答案
如果您希望将依赖项遥测链接到请求,您需要以某种方式告诉父操作是什么。详细概述可以在 the docs 中找到。
您可以使用 StartOperation
启动新的依赖项跟踪。这样,操作就会链接到父操作(下例中的请求),因此会自动设置 operation_id
和 operation_parentId
:
[HttpGet("/api/endpoint")]
public ActionResult<IEnumerable<string>> Endpoint()
{
...
using (var op = _telemetryClient.StartOperation<DependencyTelemetry>("Redis")
{
// call redis
op.Telemetry.Success = true;
}
...
}
另一个例子可以找到in the docs .
如果你看一下 the linked code ,应该很容易修改以使用 StartOperation
。
关于azure - Application Insights - 为什么自定义依赖项会从错误的父级进行跟踪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70688286/