【问题标题】:Tagging metrics in Application Insights for NodeJS在 Application Insights for NodeJS 中标记指标
【发布时间】:2016-09-27 13:06:02
【问题描述】:

我目前正在将 Application Insights 添加到我的 NodeJS 应用程序中,我已安装包并成功传输数据,但是我想在每个数据点发送时添加额外的标签。

查看文档,似乎遥测处理器是执行此操作的地方,但使用下面的代码我看不到 Azure 门户中的标签。

var TraceProcessor = function (envelope) {
    envelope.tags['TestTag'] = 'Test Tag';
    return true;
};
module.exports = TraceProcessor;

我可以看到正在执行的代码和正在添加的标签,但在 Azure 门户中看不到此标签以对其进行过滤。

我是否正确添加了标签?如果是,我在哪里可以在门户中按这些过滤数据?

【问题讨论】:

标签: node.js azure azure-application-insights


【解决方案1】:

我认为您正在寻找的是“自定义属性”(上面的示例使用自定义属性命名“标签”)。 SDK 中的所有方法通常都允许您传递字符串键:值对的字典,并且这些属性与所有这些事件一起传播。对于所有非指标调用,例如 TrackEvent,您实际上可以传递自定义属性的字典自定义指标的字典(字符串:双精度)。

c# sdk in TelemetryClient:

public void TrackMetric(string name, double value, IDictionary<string, string> properties = null)

或在 trackevent 调用中使用指标和属性:

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; });

您发送到那里的任何属性应该在指标浏览器或分析查询工具中显示为过滤选项。

【讨论】:

  • 感谢您的回复 - 也许我理解错了,使用 TrackMetric 和 TrackEvent 不会强迫我手动实现事件跟踪而不是使用自动遥测吗?
【解决方案2】:

所以我想到了这一点,最终证明它是我最初的方法和 John 建议的方法的结合。

var TraceProcessor = function (envelope) {
    envelope.data.baseData.properties['TraceID'] = 'trace1';
    return true;
};
module.exports = TraceProcessor;

自定义属性确实是我需要的,但是我已经拥有的遥测处理器是能够通过自动遥测为每个请求执行此操作所需要的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    相关资源
    最近更新 更多