azure - Application Insights - 为什么自定义依赖项会从错误的父级进行跟踪?

标签 azure .net-core azure-application-insights

我们有一个 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);

enter image description here

最佳答案

如果您希望将依赖项遥测链接到请求,您需要以某种方式告诉父操作是什么。详细概述可以在 the docs 中找到。

您可以使用 StartOperation 启动新的依赖项跟踪。这样,操作就会链接到父操作(下例中的请求),因此会自动设置 operation_idoperation_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/

相关文章:

powershell - 使用 Azure powershell 列出容器上的现有 SASToken

c# - 将 .NET Core 类库引用添加到 UWP 应用程序时,它显示 "Unable to add a reference to project..."

c# - 强名称程序集 - 必须更改数千个程序集

c# - 在 Mac 上分析 .net core 应用程序?

c# - 如何使用 Application Insights 覆盖或忽略 cloud_RoleInstance

azure - 使用 net.tcp 端点监视 WCF 服务

asp.net-mvc - Azure Web 角色并不总是显示移动 View ?

javascript - 使用 Azure 发布静态网站

c# - 在 CodeBehind C# SQL 中访问 SCOPE_IDENTITY()

c# - Azure 函数不会将自定义事件记录到应用程序洞察中