0

我有几个功能应用程序(FunctionApp1 和 FunctionApp2)。FunctionApp1 将消息发送到由 FunctionApp2 使用的服务总线队列。

执行流时,Application Insights 中的日志会显示组合流的日志。当我在 Application Insights 的选项卡中检查 FunctionApp1 的特定日志时Performance,它也会显示 FunctionApp2 的日志,反之亦然。

host.json我试图通过在文件中为 FunctionApp1设置日志级别来执行 FunctionApp1 时禁用 FunctionApp2 的日志记录,如下所示:

{
    "logging": {
        "LogLevel": {
            "Function.FunctionApp2":"None",
            "default":"debug"
        }
    }
}

这将完全禁用 FunctionApp2 的日志。

如何设置这样,当请求 FunctionApp1 的日志时,仅显示其日志并且与 FunctionApp2 相同?

更新

我尝试EnableDependencyTracking在 FunctionApp1 的 host.json 文件中设置为 false,如下所示:

{
    "logging": {
        "LogLevel": {
            "default":"debug"
        },
        "applicationInsights": {
            "enableDependencyTracking": false
        },
        ....
    }
}

这也不起作用。

4

1 回答 1

1

TelemetryContext有一个称为Parent operation Id的属性。根据文档,它跟踪遥测项目的直接父项。因此,我像这样使用自定义遥测更新了遥测的父级(以下代码在 FunctionApp2 中实现):

var dependency = new DependencyTelemetry();
// Appended UTC ticks to GUID to avoid conflicting Azure's generated GUIDs in case any future ParentId matches Azure's already generated GUID.
dependency.Context.Operation.ParentId = $"{Guid.NewGuid():N}{DateTimeOffset.UtcNow.Ticks}";
_telemetryClient.TrackDependency(dependency);

使用依赖注入将其DependencyTelemetry注入到函数应用程序中,如下所示:

_telemetryClient = new TelemetryClient(telemetryConfiguration);

TelemetryConfiguration被添加为Startup.cs类中的服务:

services.Configure<TelemetryConfiguration>((x) =>
            {
                x.InstrumentationKey = Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
                x.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());

            });

有关上述代码的更多详细信息,请参阅 ApplicationInsight 的问题1152 。

回到更新遥测操作的父 ID,它确保 FunctionApp2 的遥测未链接到 FunctionApp1 的遥测。

于 2021-08-12T05:57:32.693 回答