在 Application Insights for NodeJS 中标记指标
Tagging metrics in Application Insights for NodeJS
我目前正在将 Application Insights 添加到我的 NodeJS 应用程序中,我已经安装了包并成功传输了数据,但是我想在每个数据点发送时添加额外的标签。
查看文档,遥测处理器似乎是执行此操作的地方,但使用下面的代码我无法在 Azure 门户中看到标签。
var TraceProcessor = function (envelope) {
envelope.tags['TestTag'] = 'Test Tag';
return true;
};
module.exports = TraceProcessor;
我可以看到正在执行的代码和正在添加的标签,但在 Azure 门户中看不到要按它筛选的标签。
我添加的标签是否正确?如果正确,我可以在门户网站的何处根据这些标签过滤数据?
我认为您正在寻找的是 "custom properties"(上面的示例使用自定义 属性 named "Tag")。 SDK 中的所有方法通常都允许您传递字符串 key:value 对的字典,并且这些属性随所有这些事件一起传递。对于所有非度量调用,例如 TrackEvent,您实际上可以传递一个自定义属性字典 和 一个自定义度量字典 (string:double)。
c# sdk 在 TelemetryClient
:
public void TrackMetric(string name, double value, IDictionary<string, string> properties = null)
或在跟踪事件调用中使用指标和属性:
public void TrackEvent(string name, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
JavaScript SDK(好吧,无论如何来自 ts 接口),来自 AppInsights.prototype
trackMetric(name: string, average: number, sampleCount?: number, min?: number, max?: number, properties?: { [name: string]: string; });
您发送到那里的任何属性应该在指标浏览器或分析查询工具中显示为过滤选项。
所以我想出了这个办法,最终证明它是我原来的方法和约翰建议的方法的结合。
var TraceProcessor = function (envelope) {
envelope.data.baseData.properties['TraceID'] = 'trace1';
return true;
};
module.exports = TraceProcessor;
自定义属性确实是我所需要的,但我已经拥有的遥测处理器是能够通过自动遥测为每个请求执行此操作所需要的。
我目前正在将 Application Insights 添加到我的 NodeJS 应用程序中,我已经安装了包并成功传输了数据,但是我想在每个数据点发送时添加额外的标签。
查看文档,遥测处理器似乎是执行此操作的地方,但使用下面的代码我无法在 Azure 门户中看到标签。
var TraceProcessor = function (envelope) {
envelope.tags['TestTag'] = 'Test Tag';
return true;
};
module.exports = TraceProcessor;
我可以看到正在执行的代码和正在添加的标签,但在 Azure 门户中看不到要按它筛选的标签。
我添加的标签是否正确?如果正确,我可以在门户网站的何处根据这些标签过滤数据?
我认为您正在寻找的是 "custom properties"(上面的示例使用自定义 属性 named "Tag")。 SDK 中的所有方法通常都允许您传递字符串 key:value 对的字典,并且这些属性随所有这些事件一起传递。对于所有非度量调用,例如 TrackEvent,您实际上可以传递一个自定义属性字典 和 一个自定义度量字典 (string:double)。
c# sdk 在 TelemetryClient
:
public void TrackMetric(string name, double value, IDictionary<string, string> properties = null)
或在跟踪事件调用中使用指标和属性:
public void TrackEvent(string name, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
JavaScript SDK(好吧,无论如何来自 ts 接口),来自 AppInsights.prototype
trackMetric(name: string, average: number, sampleCount?: number, min?: number, max?: number, properties?: { [name: string]: string; });
您发送到那里的任何属性应该在指标浏览器或分析查询工具中显示为过滤选项。
所以我想出了这个办法,最终证明它是我原来的方法和约翰建议的方法的结合。
var TraceProcessor = function (envelope) {
envelope.data.baseData.properties['TraceID'] = 'trace1';
return true;
};
module.exports = TraceProcessor;
自定义属性确实是我所需要的,但我已经拥有的遥测处理器是能够通过自动遥测为每个请求执行此操作所需要的。