如何在javascript中获取Application Insight操作ID?

How to get Application Insights operation id in javascript?(如何在javascript中获取Application Insight操作ID?)

本文介绍了如何在javascript中获取Application Insight操作ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用javascript编写的Azure函数应用,它集成了Application Insight:

const AppInsights = require("applicationinsights");

AppInsights.setup(appInsightsInstrumentationKey);
AppInsights.defaultClient.context.tags[
    AppInsights.defaultClient.context.keys.cloudRole
        ] = "My back-end";
AppInsights.start();

模块版本为1.7.4。

我确实需要访问当前操作ID才能将其发送到我的自定义日志,以便与Azure中的AI日志关联。在我的函数中,我尝试了以下内容:

var telemetry = appInsights.defaultClient;
var oid = telemetry.context.tags["ai.operation.id"]; // does not work
var oid = telemetry.context.operation.id; // does not work

不过,AI会以某种方式收集它,这样我就可以在Azure门户中看到它:

如何在运行时访问Azure函数中的operation_id值?

推荐答案

您可以用下面这行代码尝试一下:

//operation id
var s = client.context.keys["operationId"];

我是通过DEBUG找到的,截图如下:

这篇关于如何在javascript中获取Application Insight操作ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在javascript中获取Application Insight操作ID?

基础教程推荐