2016-09-27 72 views
0

我正在将Application Insights添加到我的NodeJS应用程序中,我安装了软件包并成功传输数据,但是我想在发送每个数据点时添加其他标记。NodeJS的应用程序洞察中的标记指标

看看文档,它似乎是一个遥测处理器的地方,但使用下面的代码我看不到Azure门户中的标签。

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

我可以看到正在执行的代码和正在添加的标记,但无法在Azure门户中看到该标记进行过滤。

我是否正确地添加标签,如果是的话,我可以在门户网站中通过这些标签过滤数据?

+0

根据https://github.com/Microsoft/ApplicationInsights-node.js/blob/master/Library/Client.ts#L215源代码中'envelope'的'tag'属性的定义,它似乎是在context类的https://github.com/Microsoft/ApplicationInsights-node.js/blob/master/Library/Context.ts#L49中验证。你能否澄清你的要求? –

+0

感谢您的回复。我想要做的是能够在每个度量标准发送时添加附加信息,然后在分析数据时通过这些信息进行过滤。标签名称对于每个数据点都是相同的,但值可能不同。 从查看C#版本的见解,我认为我可以使用标签来完成此操作 - https://blogs.msdn.microsoft.com/visualstudioalm/2015/01/07/application-insights-support- for-multiple-environments-stamps-and-app-versions/ 有没有类似的NodeJS机制? –

回答

0

所以我想通了,它最终结果是我原来的方法和约翰建议的方法的组合。

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

自定义属性确实是我所需要的,但遥测处理器我已经是被需要的,以便能够与每个请求自动遥测做到这一点。

0

我认为你要找的是“自定义属性”(上面的示例使用名为的“自定义属性”标签“)。 SDK中的所有方法通常允许您传递字符串键值对的字典,并且这些属性随所有这些事件一起传送。对于所有非度量标准调用(如TrackEvent),您实际上可以传递自定义属性字典字典(字符串:double)自定义度量标准。

C#SDK在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; }); 

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

+0

感谢您的回应 - 也许我误解了,不会使用TrackMetric和TrackEvent强制我手动执行事件跟踪,而不是使用自动遥测? –